Class FileElement


  • public class FileElement
    extends Object
    The element used as left or right file for compare.
    • Constructor Detail

      • FileElement

        public FileElement​(String path,
                           FileElement.Type type)
        Creates file element for path.
        Parameters:
        path - the file path
        type - the element type
      • FileElement

        public FileElement​(String path,
                           FileElement.Type type,
                           File workDir)
        Creates file element for path.
        Parameters:
        path - the file path
        type - the element type
        workDir - the working directory of the path (can be null, then current working dir is used)
      • FileElement

        public FileElement​(String path,
                           FileElement.Type type,
                           File workDir,
                           InputStream stream)
        Parameters:
        path - the file path
        type - the element type
        workDir - the working directory of the path (can be null, then current working dir is used)
        stream - the object stream to load and write on demand, @see getFile(), to tempFile once (can be null)
    • Method Detail

      • getPath

        public String getPath()
        Returns:
        the file path
      • getFile

        public File getFile()
                     throws IOException
        Return
        • a temporary file if already created and stream is not valid
        • OR a real file from work tree: if no temp file was created (@see createTempFile()) and if no stream was set
        • OR an empty temporary file if path is "/dev/null"
        • OR a temporary file with stream content if stream is valid (not null); stream is closed and invalidated (set to null) after write to temp file, so stream is used only once during first call!
        Returns:
        the object stream
        Throws:
        IOException
      • isNullPath

        public boolean isNullPath()
        Check if path id "/dev/null"
        Returns:
        true if path is "/dev/null"
      • createTempFile

        public File createTempFile​(File directory)
                            throws IOException
        Create temporary file in given or system temporary directory.
        Parameters:
        directory - the directory for the file (can be null); if null system temporary directory is used
        Returns:
        temporary file in directory or in the system temporary directory
        Throws:
        IOException
      • cleanTemporaries

        public void cleanTemporaries()
        Delete and invalidate temporary file if necessary.
      • replaceVariable

        public String replaceVariable​(String input)
                               throws IOException
        Replace variable in input.
        Parameters:
        input - the input string
        Returns:
        the replaced input string
        Throws:
        IOException
      • addToEnv

        public void addToEnv​(Map<String,​String> env)
                      throws IOException
        Add variable to environment map.
        Parameters:
        env - the environment where this element should be added
        Throws:
        IOException