Class ExternalContentTransformation

  • All Implemented Interfaces:
    java.lang.Runnable, java.util.concurrent.Callable<byte[]>

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

      • program

        protected final java.lang.String program
      • args

        protected final java.lang.String[] args
      • timeout

        protected java.time.Duration timeout
      • logFile

        protected java.nio.file.Path logFile
      • outputFile

        protected java.nio.file.Path outputFile
      • resultCode

        protected int resultCode
      • hasRun

        protected boolean hasRun
      • result

        protected byte[] result
      • processOutput

        protected java.lang.String processOutput
    • Constructor Detail

      • ExternalContentTransformation

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

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

      • createTempFile

        public static java.nio.file.Path createTempFile​(java.lang.String extension,
                                                        byte... contents)
                                                 throws java.io.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:
        java.io.IOException - If the temp file couldn't be created.
      • resolveNodeProgram

        public static java.lang.String resolveNodeProgram​(java.lang.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()
      • screenRun

        protected void screenRun()
                          throws java.lang.IllegalStateException
        Throws:
        java.lang.IllegalStateException
      • getResult

        public byte[] getResult()
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • run

        public final void run()
        Specified by:
        run in interface java.lang.Runnable
      • call

        public byte[] call()
                    throws java.io.IOException
        Specified by:
        call in interface java.util.concurrent.Callable<byte[]>
        Throws:
        java.io.IOException
      • getException

        public java.io.IOException getException()
      • getLogFile

        public java.nio.file.Path getLogFile()
      • setLogFile

        public void setLogFile​(java.nio.file.Path logFile)
      • getOutputFile

        public java.nio.file.Path getOutputFile()
      • setOutputFile

        public void setOutputFile​(java.nio.file.Path outputFile)
      • getTimeout

        public java.time.Duration getTimeout()
      • setTimeout

        public void setTimeout​(java.time.Duration timeout)
      • getProgram

        public java.lang.String getProgram()
      • getArgs

        public java.lang.String[] getArgs()
      • getProcessOutput

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