Class ExtendedFile

java.lang.Object
java.io.File
clazzfish.monitor.io.ExtendedFile
All Implemented Interfaces:
Serializable, Comparable<File>

public final class ExtendedFile extends File
This is the extended version of the File class. It provides some additional methods which are missing in this class.

Originally this class was part of the PatternTesting project but is now transfered to here.

Author:
oliver
See Also:
  • Constructor Details

    • ExtendedFile

      public ExtendedFile(File file)
      Instantiates a new extended file.
      Parameters:
      file - the wrapped file
    • ExtendedFile

      public ExtendedFile(String filename)
      Instantiates a new extended file.
      Parameters:
      filename - the filename
    • ExtendedFile

      public ExtendedFile(File parent, String filename)
      Instantiates a new extended file.
      Parameters:
      parent - the parent
      filename - the filename
    • ExtendedFile

      public ExtendedFile(String parent, String filename)
      Instantiates a new extended file.
      Parameters:
      parent - the parent
      filename - the filename
    • ExtendedFile

      public ExtendedFile(URI fileURI)
      Instantiates a new extended file.
      Parameters:
      fileURI - the file uri
    • ExtendedFile

      public ExtendedFile(File parent, File file)
      Instantiates a new extended file.
      Parameters:
      parent - the parent
      file - the file
  • Method Details

    • validate

      public static void validate(File file) throws FileNotFoundException
      Validates the given file and throws an FileNotFoundException if it is not a valid file. This is the case if
      1. the file does not exist or
      2. the file exists, but is not a file but a directory.

      If the file does not exist it tr tries guess the real filename. E.g. one of the common platform problems is that Windows does not support case sensitive filenames whereas Unix platforms distinguish between upper/lowercase in filenames. "readme.txt" and "README.TXT" are two different files under Unix but not on Windows.

      Parameters:
      file - the file
      Throws:
      FileNotFoundException - the file not found exception
      Since:
      1.7
    • createDir

      public static void createDir(File dir)
      Creates the given directory if it does not exist.
      Parameters:
      dir - directory to be created
    • createTmpdir

      public static File createTmpdir(String prefix, String suffix) throws IOException
      Creates a directory in the temp directory.
      Parameters:
      prefix - the prefix
      suffix - the suffix
      Returns:
      the directory
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getTmpdir

      public static File getTmpdir(String filename)
      Gets the tmpdir.
      Parameters:
      filename - the filename
      Returns:
      the tmpdir
    • toStringArray

      public static String[] toStringArray(List<File> files)
      Converts a list with files into a string array.

      Since 1.7 this method was moved from the (now deprecated) FileHelper to this class here.

      Parameters:
      files - the files
      Returns:
      the string[]
      Since:
      1.5 (27.08.2014)
    • getParentExtendedFile

      public ExtendedFile getParentExtendedFile()
      Gets the parent as ExtendedFile. This method was introduced because File.getParent() and File.getParentFile() also exists.
      Returns:
      the parent extended file
    • normalize

      public File normalize()
      Normalizes a file, analogous to FilenameUtils.normalize(String). But before we normalize it we try to ask to OS for the canonical path for it.
      Returns:
      the normalized file
    • normalize

      public static File normalize(File file)
      Normalizes a file, analogous to FilenameUtils.normalize(String). But before we normalize it we try to ask to OS for the canonical path for it.
      Parameters:
      file - the file
      Returns:
      the file
    • endsWith

      public boolean endsWith(File extension)
      With this method you can ask if a file ends with the given extension.
      Parameters:
      extension - the extension - must be a relative path e.g. "WEB-INF/classes"
      Returns:
      true, if successful
    • getBaseDir

      public File getBaseDir(File extension)
      Returns the base of the given file. The 'base' is the given file without the extension. Remember, the extension parameter is of type File, so it must be a file (not a file extension like ".txt").
      Parameters:
      extension - the extension - must be a relative path e.g. "WEB-INF/classes"
      Returns:
      the file, e.g. "/tmp/web"
    • createOutputStreamFor

      public static OutputStream createOutputStreamFor(File file)
      Creates the output stream of the file. As fallback stdout will be used if the output stream cannot be created.
      Parameters:
      file - the file
      Returns:
      the output stream
      Since:
      1.7
    • createOutputStream

      public OutputStream createOutputStream()
      Creates the output stream of the file. As fallback stdout will be used if the output stream cannot be created.
      Returns:
      the output stream
      Since:
      1.7
    • equals

      public boolean equals(Object obj)
      Comparing two files is not so easy as it seems to be. On unix systems or Mac OS-X you can see the same file via two different mount points or as two different hard links. If you are on *nix you can use the inode to compare but how to get the inode?
      Overrides:
      equals in class File
      Parameters:
      obj - the other file
      Returns:
      true, if successful
      See Also:
    • hashCode

      public int hashCode()
      Hash code.
      Overrides:
      hashCode in class File
      Returns:
      the int
      See Also: