Class FileUtils

java.lang.Object
net.ssehub.easy.basics.io.FileUtils

public class FileUtils extends Object
Some file utility methods (may partially be taken from commons.io but this is currently no defined as dependency of this bundle - see standalone).
Author:
Holger Eichelberger
  • Field Details

    • IS_WINDOWS

      private static final boolean IS_WINDOWS
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • isFileURI

      public static boolean isFileURI(URI uri)
      Returns whether the given uri is a file URI as returned, e.g., by a File.
      Parameters:
      uri - the URI (ignored if null)
      Returns:
      true for a file URI, false else
    • isFileURL

      public static boolean isFileURL(URL url)
      Returns whether the given url is a JAR URL as returned, e.g., by a classloader.
      Parameters:
      url - the URL (ignored if null)
      Returns:
      true for a JAR URL, false else
    • copyFile

      public static void copyFile(File target, File source) throws IOException
      Copies a file.
      Parameters:
      target - the target file
      source - the source file
      Throws:
      IOException - in any case of I/O problem, trying to close the involved files before end if possible
    • copyToFile

      public static void copyToFile(File file, InputStream in) throws IOException
      Copies the contents of in at the current position to file. Does not attempt to close in. Uses a default buffer of size 1024.
      Parameters:
      file - the file to write to
      in - the input stream
      Throws:
      IOException - in any case of I/O problem, trying to close file before end if possible
    • copyToFile

      public static void copyToFile(File file, InputStream in, byte[] buffer) throws IOException
      Copies the contents of in at the current position to file. Does not attempt to close in. Uses a default buffer of size 1024.
      Parameters:
      file - the file to write to
      in - the input stream
      buffer - a copy buffer (if null a default one of size 1024 is used)
      Throws:
      IOException - in any case of I/O problem, trying to close file before if possible
    • closeQuietly

      public static void closeQuietly(Closeable closeable)
      Closes a closeable quietly, i.e., without exception.
      Parameters:
      closeable - the closeable
    • createIfNotExists

      public static void createIfNotExists(File file)
      Creates a (physical) file if it does not exist.
      Parameters:
      file - the file (may be null, ignored then)
    • createTmpDir

      public static File createTmpDir(String name)
      Creates a temporary directory and deletes an existing one if it already exists. Deletion on exit of JVM is enabled for the resulting directory.
      Parameters:
      name - the name of the directory within the standard temporary folder
      Returns:
      the temporary directory
    • createTmpDir

      public static File createTmpDir(String name, boolean deleteIfExists)
      Creates a temporary directory. Deletion on exit of JVM is enabled for the resulting directory.
      Parameters:
      name - the name of the directory within the standard temporary folder
      deleteIfExists - delete an existing one if it already exists
      Returns:
      the temporary directory
    • appendToLogFile

      public static void appendToLogFile(String text)
      Appends text to "easy-debug.log" in user home. [debugging]
      Parameters:
      text - the text
    • appendToFile

      public static void appendToFile(File file, String text)
      Appends text to file. [debugging]
      Parameters:
      file - the file
      text - the text
    • resolve

      public static final File resolve(File file)
      Resolves a file or a symlink.
      Parameters:
      file - the file to be resolved
      Returns:
      the resolved file or file if it cannot be resolved
    • resolve

      public static final File[] resolve(File... files)
      Resolves files/symlinks.
      Parameters:
      files - the files to be resolved, may be null
      Returns:
      the resolved files or null
      See Also:
    • listFiles

      public static final File[] listFiles(File file)
      Lists files in file after resolving file and its contained files.
      Parameters:
      file - the file to list the files for, may be null
      Returns:
      the resolved contained files
      See Also: