java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_base.FileUtil

public class FileUtil extends Object
Helper for creating files etc.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • RANDOM

      private static final SecureRandom RANDOM
    • SYSTEM_TMP_FOLDER

      public static final File SYSTEM_TMP_FOLDER
    • userTmpFolder

      private static File userTmpFolder
  • Constructor Details

    • FileUtil

      public FileUtil()
  • Method Details

    • getUserTmpFolder

      public static File getUserTmpFolder()
      Returns the folder which the user wants to use a temporary directory. The default is the systems tmp.
      Returns:
      the folder which the user wants to use a temporary directory.
    • setUserTmpFolder

      public static void setUserTmpFolder(File newUserTmpFolder)
      Sets a folder which represents a location for temporary data. This does not necessarily needs to be the systems tmp folder but any folder the user would like to use.
      Parameters:
      newUserTmpFolder - the new folder - it should be a directory and existent.
    • createFolderWithRandomNumberInDirectory

      public static File createFolderWithRandomNumberInDirectory(File folder, String prefix)
      Creates a folder with a random number attached to the prefix in a given folder. The new folder will look like: {givenfolder}/prefix-1234/
      Parameters:
      folder - the folder to use
      prefix - the prefix for the newly created folder.
      Returns:
      the new folder (not yet created)
    • createFolderWithRandomNumberInUserTmp

      public static File createFolderWithRandomNumberInUserTmp(String prefix)
      Creates a new folder in the user defined tmp folder. The new folder will look like: {userDefinedTmp}/prefix-1234/ (1234 is a randomly generated number)
      Parameters:
      prefix - the prefix to use for the folder
      Returns:
      the new folder (not yet created)
    • createFileWithRandomNumber

      public static File createFileWithRandomNumber(File folder, String prefix, String suffix)
      Create a new file in the given directory with prefix and suffix and a random number. The file path will look like: {folder}/{prefix}1234{suffix}
      Parameters:
      folder - the folder to use
      prefix - the prefix (usually the file name)
      suffix - suffix (usually the file extension) like .txt (the dot needs to be included
      Returns:
      the file to use.
    • createFileWithRandomNumber

      public static File createFileWithRandomNumber(String prefix, String suffix)
      Create a new file in the user defined tmp directory with prefix and suffix and a random number. The file path will look like: {userDefinedTmp}/{prefix}1234{suffix}
      Parameters:
      prefix - the prefix (usually the file name)
      suffix - suffix (usually the file extension) like .txt (the dot needs to be included
      Returns:
      the file to use.
    • createFileWithRandomNumberInUserTmp

      public static File createFileWithRandomNumberInUserTmp(String prefix, String suffix)
      Create a new file in the user defined tmp directory with prefix and suffix and a random number. The file path will look like: {userDefinedTmp}/{prefix}1234{suffix}
      Parameters:
      prefix - the prefix (usually the file name)
      suffix - suffix (usually the file extension) like .txt (the dot needs to be included
      Returns:
      the file to use.
    • getRandomPositiveNumber

      public static Long getRandomPositiveNumber()
      Returns a positive random number which can be used to create file names with random numbers in it.
      Returns:
      a positive random number
    • lineCount

      public static long lineCount(File file)
      Determines the count of lines in a file in a fast way. If counts the number of newlines. Thus, if the file contains only one row and no newline it will return zero.
      Parameters:
      file - the file to use
      Returns:
      the number of lines in the file
    • getCanonicalPathIfPossible

      public static String getCanonicalPathIfPossible(File file)
      Returns the canonical path (resolved symlink, and relative paths) of a file if possible. If this calls fails, then the absolute path is returned.
      Parameters:
      file - the file to get the canonical path from
      Returns:
      the canonical path or if not possible, the absolute path
    • getCanonicalPathIfPossible

      public static String getCanonicalPathIfPossible(String filePath)
      Returns the canonical path (resolved symlink, and relative paths) of a file if possible. If this calls fails, then the absolute path is returned.
      Parameters:
      filePath - the file patha s a string. This can be a relative file path like ./fooBar
      Returns:
      the canonical path or if not possible, the absolute path