Class Unix4jUtils

java.lang.Object
uk.ac.ebi.utils.opt.io.Unix4jUtils

public class Unix4jUtils extends Object

Utilities for the great Unix4j library.

WARNING: In order to avoid too many dependency for jUtils, you have to declare the dependency on both Unix4j and EasyStream (copy-paste them from the junit-io's pom).

Author:
brandizi
Date:
22 Mar 2018
  • Constructor Details

    • Unix4jUtils

      public Unix4jUtils()
  • Method Details

    • unixFilter

      public static InputStream unixFilter(org.unix4j.builder.To command)

      Pipes the output of a Unix4j command

      This sends an InputStream to a Unix4j command and returns another input stream that is the output of that command.

      Differently from Command.join(Command), this emulates the pipe '|' operator in Unix in a way such that the command's output can be sent to some Java input consumer, after it has been filtered by the command.

      Also note that we're doing this dynamically, the initial input stream is processed while a consumer reads the stream returned by this method. This is achieved through the EasyStream library

    • sedFilter

      public static InputStream sedFilter(InputStream inStream, String sedScript)
      Just a wrapper that uses #unixFilter(To, InputStream) to process an input stream via the sed command.
    • sedFilter

      public static InputStream sedFilter(InputStream inStream, String regex, String repl)
      Just a wrapper of sedFilter(InputStream, String) that tweaks a stream dynamically, to replace text based on a regular expression. The repl parameter accepts backreferences like \1.
      Returns:
      the filter that does the replacement, as an InputStream in which the filtering operation is invoked dynamically while, the stream is read.