Class FileUtil
java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_base.FileUtil
Helper for creating files etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerprivate static final SecureRandomstatic final Fileprivate static File -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FilecreateFileWithRandomNumber(File folder, String prefix, String suffix) Create a new file in the given directory with prefix and suffix and a random number.static FilecreateFileWithRandomNumber(String prefix, String suffix) Create a new file in the user defined tmp directory with prefix and suffix and a random number.static FilecreateFileWithRandomNumberInUserTmp(String prefix, String suffix) Create a new file in the user defined tmp directory with prefix and suffix and a random number.static FilecreateFolderWithRandomNumberInDirectory(File folder, String prefix) Creates a folder with a random number attached to the prefix in a given folder.static FileCreates a new folder in the user defined tmp folder.static StringReturns the canonical path (resolved symlink, and relative paths) of a file if possible.static StringgetCanonicalPathIfPossible(String filePath) Returns the canonical path (resolved symlink, and relative paths) of a file if possible.static LongReturns a positive random number which can be used to create file names with random numbers in it.static FileReturns the folder which the user wants to use a temporary directory.static longDetermines the count of lines in a file in a fast way.static voidsetUserTmpFolder(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
-