Class ExternalContentTransformation

  • All Implemented Interfaces:
    Runnable, Callable<byte[]>

    public class ExternalContentTransformation
    extends Object
    implements Runnable, Callable<byte[]>
    Utility class for using external programs in transforming content.
    Since:
    2.2
    Author:
    Sina Madani
    • Field Detail

      • program

        protected final String program
      • args

        protected final String[] args
      • logFile

        protected Path logFile
      • outputFile

        protected Path outputFile
      • resultCode

        protected int resultCode
      • hasRun

        protected boolean hasRun
      • result

        protected byte[] result
      • processOutput

        protected String processOutput
    • Constructor Detail

      • ExternalContentTransformation

        protected ExternalContentTransformation​(String program,
                                                Object... arguments)
      • ExternalContentTransformation

        public ExternalContentTransformation​(Path outputFile,
                                             String program,
                                             Object... arguments)
    • Method Detail

      • createTempFile

        public static Path createTempFile​(String extension,
                                          byte... contents)
                                   throws IOException
        Convenience method for temporary files used in intermediate transformations.
        Parameters:
        extension - The file extension.
        contents - The initial contents of the file. May be null.
        Returns:
        The absolute path of the temporary file.
        Throws:
        IOException - If the temp file couldn't be created.
      • resolveNodeProgram

        public static String resolveNodeProgram​(String program)
        Parameters:
        program - The Node.js program name.
        Returns:
        The absolute path of the command needed to invoke the program.
      • getResultCode

        public int getResultCode()
      • run

        public final void run()
        Specified by:
        run in interface Runnable
      • getLogFile

        public Path getLogFile()
      • setLogFile

        public void setLogFile​(Path logFile)
      • getOutputFile

        public Path getOutputFile()
      • setOutputFile

        public void setOutputFile​(Path outputFile)
      • getTimeout

        public Duration getTimeout()
      • setTimeout

        public void setTimeout​(Duration timeout)
      • getProgram

        public String getProgram()
      • getArgs

        public String[] getArgs()
      • getProcessOutput

        public String getProcessOutput()
        Returns:
        The stdout of the invoked program.
        Throws:
        IllegalStateException - If the program hasn't been run yet.