Class FileUtil
- java.lang.Object
-
- ch.supertomcat.supertomcatutils.io.FileUtil
-
public final class FileUtil extends Object
Class which provides methods to get directory, filename, ... from a path to a file
-
-
Field Summary
Fields Modifier and Type Field Description static StringFILE_SEPERATORPath-Seperator for the actual operating systemstatic charFILE_SEPERATOR_CHAR_LINUXPath-Seperator from Linuxstatic charFILE_SEPERATOR_CHAR_WINDOWSPath-Seperator from Windowsstatic StringFILE_SEPERATOR_LINUXPath-Seperator from Linuxstatic StringFILE_SEPERATOR_WINDOWSPath-Seperator from Windowsstatic intFILENAME_ALLFilter only not allowed chars from paths and filenamesstatic intFILENAME_ASCII_ONLYFilter all non-ascii chars from paths and filenamesstatic intFILENAME_ASCII_UMLAUTFilter all non-ascii and non-umlaut chars from paths and filenamesstatic intFILENAME_LENGTH_LIMITMaximum length of a filenamestatic intPATH_WITHOUT_FILENAME_LENGTH_LIMITMaximum length of a path without filenamestatic intWINDOWS_MAX_FOLDER_PATH_LENGTHWindows Max Path Length for a folder only.static intWINDOWS_MAX_PATH_LENGTHWindows Max Path Length (Minus 1, because of Null Terminator)static intWINDOWS_MIN_FILENAME_LENGTHWindows Min Filename Length (8 for name, 1 for dot, 3 for extension)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancheckIsSameOrSubFolder(String path, String parentPath)Checks if path is a subfolder of parentPath It will also return true, if the path is not a direct subfolder.static StringfilterFilename(String filename, int mode)This method filters not allowed chars in filenamesstatic StringfilterPath(String path, int mode)This method filters not allowed chars in paths (including filename if available)static StringgetDirectory(String file)Returns the folderstatic StringgetFileExtension(String file)Returns the extension of a filestatic StringgetFilename(String file)Returns the filenamestatic StringgetFilePrefix(String file)Returns the filename without the extensionstatic StringgetNumberedFilename(String filename, int number)Returns a filename with "#" replaced by the given number If there are more # as the numbers length is than the # is replaced by zero.static StringgetPathFromFile(File file)Returns the path of a filestatic StringgetZeroFilledNumber(int number, int len)Returns the number with leading zeros Example: Number is 2 and length is 4: This method returns: 0002 If the length is smaller than the count of chars of the number the length is automatically increasedstatic StringlTrim(String str)Trims the start of a pathstatic StringpathRTrim(String path)Trims a pathstatic StringreduceFilenameLength(String filename)Method to reduce length of filename, because paths in Windows Explorer can only be have 255 chars.static StringreduceFilenameLength(String filename, int lengthLimit)Method to reduce length of filename, because paths in Windows Explorer can only be have 255 chars.static StringreducePathLength(String folder)Method to reduce length of path (without filename), because paths in Windows Explorer can only be have 255 chars.static StringreducePathLength(String folder, int lengthLimit)Method to reduce length of path (without filename), because paths in Windows Explorer can only be have 255 chars.static StringreduceTextLength(String text, int limit)Method to reduce lenght of a String which is not a filename or a path.static StringrTrim(String str)Trims the end of a path
-
-
-
Field Detail
-
FILE_SEPERATOR
public static final String FILE_SEPERATOR
Path-Seperator for the actual operating system
-
FILE_SEPERATOR_WINDOWS
public static final String FILE_SEPERATOR_WINDOWS
Path-Seperator from Windows- See Also:
- Constant Field Values
-
FILE_SEPERATOR_CHAR_WINDOWS
public static final char FILE_SEPERATOR_CHAR_WINDOWS
Path-Seperator from Windows- See Also:
- Constant Field Values
-
FILE_SEPERATOR_LINUX
public static final String FILE_SEPERATOR_LINUX
Path-Seperator from Linux- See Also:
- Constant Field Values
-
FILE_SEPERATOR_CHAR_LINUX
public static final char FILE_SEPERATOR_CHAR_LINUX
Path-Seperator from Linux- See Also:
- Constant Field Values
-
WINDOWS_MAX_PATH_LENGTH
public static final int WINDOWS_MAX_PATH_LENGTH
Windows Max Path Length (Minus 1, because of Null Terminator)- See Also:
- Constant Field Values
-
WINDOWS_MIN_FILENAME_LENGTH
public static final int WINDOWS_MIN_FILENAME_LENGTH
Windows Min Filename Length (8 for name, 1 for dot, 3 for extension)- See Also:
- Constant Field Values
-
WINDOWS_MAX_FOLDER_PATH_LENGTH
public static final int WINDOWS_MAX_FOLDER_PATH_LENGTH
Windows Max Path Length for a folder only.- See Also:
- Constant Field Values
-
PATH_WITHOUT_FILENAME_LENGTH_LIMIT
public static final int PATH_WITHOUT_FILENAME_LENGTH_LIMIT
Maximum length of a path without filename- See Also:
- Constant Field Values
-
FILENAME_LENGTH_LIMIT
public static final int FILENAME_LENGTH_LIMIT
Maximum length of a filename- See Also:
- Constant Field Values
-
FILENAME_ASCII_ONLY
public static final int FILENAME_ASCII_ONLY
Filter all non-ascii chars from paths and filenames- See Also:
- Constant Field Values
-
FILENAME_ASCII_UMLAUT
public static final int FILENAME_ASCII_UMLAUT
Filter all non-ascii and non-umlaut chars from paths and filenames- See Also:
- Constant Field Values
-
FILENAME_ALL
public static final int FILENAME_ALL
Filter only not allowed chars from paths and filenames- See Also:
- Constant Field Values
-
-
Method Detail
-
getDirectory
public static String getDirectory(String file)
Returns the folder- Parameters:
file- Path to the file- Returns:
- Pfad zum Verzeichnis
-
getFilename
public static String getFilename(String file)
Returns the filename- Parameters:
file- Path to the file- Returns:
- Filename
-
getFileExtension
public static String getFileExtension(String file)
Returns the extension of a file- Parameters:
file- Path to the file or filename- Returns:
- Fileextension
-
getFilePrefix
public static String getFilePrefix(String file)
Returns the filename without the extension- Parameters:
file- Path to the file or filename- Returns:
- Filename without extension
-
getPathFromFile
public static String getPathFromFile(File file)
Returns the path of a file- Parameters:
file- File- Returns:
- Path
-
checkIsSameOrSubFolder
public static boolean checkIsSameOrSubFolder(String path, String parentPath)
Checks if path is a subfolder of parentPath It will also return true, if the path is not a direct subfolder. And if path and parentPath are the same, this method will also return true! This method does not check if the folders exist! Example: parentPath = C:\ path = C:\example -- this returns true Example: parentPath = C:\ path = C:\example\something\bla\blub -- this returns true- Parameters:
path- PathparentPath- Parent Path- Returns:
- TRUE if it is the same folder or a subfolder
-
lTrim
public static String lTrim(String str)
Trims the start of a path- Parameters:
str- Path- Returns:
- Path
-
rTrim
public static String rTrim(String str)
Trims the end of a path- Parameters:
str- Path- Returns:
- Path
-
pathRTrim
public static String pathRTrim(String path)
Trims a path- Parameters:
path- Path- Returns:
- Path
-
getNumberedFilename
public static String getNumberedFilename(String filename, int number)
Returns a filename with "#" replaced by the given number If there are more # as the numbers length is than the # is replaced by zero. Example: The filename is "file###name" and the number is 2, then this method will return this: "file002name"- Parameters:
filename- Filenamenumber- Number- Returns:
- Filename
-
getZeroFilledNumber
public static String getZeroFilledNumber(int number, int len)
Returns the number with leading zeros Example: Number is 2 and length is 4: This method returns: 0002 If the length is smaller than the count of chars of the number the length is automatically increased- Parameters:
number- Numberlen- Length- Returns:
- Number with leading zeros
-
reducePathLength
public static String reducePathLength(String folder)
Method to reduce length of path (without filename), because paths in Windows Explorer can only be have 255 chars.- Parameters:
folder- Path without Filename- Returns:
- Reduced Path
-
reducePathLength
public static String reducePathLength(String folder, int lengthLimit)
Method to reduce length of path (without filename), because paths in Windows Explorer can only be have 255 chars.- Parameters:
folder- Path without FilenamelengthLimit- Limit- Returns:
- Reduced Path
-
reduceFilenameLength
public static String reduceFilenameLength(String filename)
Method to reduce length of filename, because paths in Windows Explorer can only be have 255 chars.- Parameters:
filename- Filename- Returns:
- Reduced Filename
-
reduceFilenameLength
public static String reduceFilenameLength(String filename, int lengthLimit)
Method to reduce length of filename, because paths in Windows Explorer can only be have 255 chars.- Parameters:
filename- FilenamelengthLimit- Limit- Returns:
- Reduced Filename
-
reduceTextLength
public static String reduceTextLength(String text, int limit)
Method to reduce lenght of a String which is not a filename or a path.- Parameters:
text- Textlimit- Limit- Returns:
- Reduced Text
-
filterPath
public static String filterPath(String path, int mode)
This method filters not allowed chars in paths (including filename if available)- Parameters:
path- Pathmode- Mode- Returns:
- Filtered path
-
-