Class FileUtil
java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_base.FileUtil
Helper for creating files etc.
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final org.slf4j.Logger
private static final SecureRandom
static final File
private static File
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
createFileWithRandomNumber
(File folder, String prefix, String suffix) Create a new file in the given directory with prefix and suffix and a random number.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.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.static File
createFolderWithRandomNumberInDirectory
(File folder, String prefix) Creates a folder with a random number attached to the prefix in a given folder.static File
Creates a new folder in the user defined tmp folder.static String
Returns the canonical path (resolved symlink, and relative paths) of a file if possible.static String
getCanonicalPathIfPossible
(String filePath) Returns the canonical path (resolved symlink, and relative paths) of a file if possible.static Long
Returns a positive random number which can be used to create file names with random numbers in it.static File
Returns the folder which the user wants to use a temporary directory.static long
Determines the count of lines in a file in a fast way.static void
setUserTmpFolder
(File newUserTmpFolder) Sets a folder which represents a location for temporary data.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
RANDOM
-
SYSTEM_TMP_FOLDER
-
userTmpFolder
-
-
Constructor Details
-
FileUtil
public FileUtil()
-
-
Method Details
-
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
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
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 useprefix
- the prefix for the newly created folder.- Returns:
- the new folder (not yet created)
-
createFolderWithRandomNumberInUserTmp
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
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 useprefix
- 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
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
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
Returns a positive random number which can be used to create file names with random numbers in it.- Returns:
- a positive random number
-
lineCount
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
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
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
-