Package slash.common.io
Class Files
java.lang.Object
slash.common.io.Files
Provides file and file name functionality.
- Author:
- Christian Pesch
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Fileabsolutize(File file) static <T> StringasLogString(List<T> list) Joins a list into a human-readable, English, uncapped string for log output, e.g.static StringcalculateConvertFileName(File file, String extension, int fileNameLength) static voidcheckDirectory(File directory) static voidcollectFiles(File path, String... extensions) Collects files below the given path with the given extension(s).collectFiles(List<File> files) static intstatic StringcreateReadablePath(File file) static StringcreateReadablePath(URL url) static File[]createTargetFiles(File pattern, int fileCount, String extension, int fileNameLength) static StringextractFileName(String path) static FilefindExistingPath(File path) static StringgenerateChecksum(File file) static StringgenerateChecksum(InputStream inputStream) static StringgetExtension(File file) static StringgetExtension(String name) static StringgetExtension(URL url) static StringgetExtension(List<URL> urls) static CompactCalendargetLastModified(File file) static StringlastPathFragment(String path, int maximumLength) static voidrecursiveDelete(File path) static StringremoveExtension(String name) Remove the extension of the given file name, if there is any.static ResolvableLinkresolveLink(File file) Resolves a file that may be an indirection to another file or directory: a Windows shortcut (.lnk) or a macOS Finder alias.static StringsetExtension(String name, String extension) Replace the extension of the given file name with the given extension.static voidsetLastModified(File file, Long lastModified) static voidsetLastModified(File file, CompactCalendar lastModified) static StringshortenPath(String path, int maximumLength) static Filestatic URLConverts a URL or local (possibly relative or space-bearing) path string to aURL, falling back to file semantics when the string is not a valid absolute URI.static voidwritePartialFile(InputStream inputStream, long fileSize, File file)
-
Constructor Details
-
Files
public Files()
-
-
Method Details
-
getExtension
- Parameters:
file- the file to find the extension- Returns:
- the extension of the file, which are the characters starting with the last dot in the file name in lowercase characters
-
getExtension
- Parameters:
name- the file name to find the extension- Returns:
- the extension of a file name, which are the characters starting with the last dot in the file name in lowercase characters
-
getExtension
-
getExtension
-
resolveLink
Resolves a file that may be an indirection to another file or directory: a Windows shortcut (.lnk) or a macOS Finder alias.- Parameters:
file- the file to inspect- Returns:
- a
ResolvableLinkfor the target, or null if the file is not such an indirection - Throws:
IOException- if the file cannot be read
-
removeExtension
Remove the extension of the given file name, if there is any.- Parameters:
name- the file name to remove the extension- Returns:
- the file name without an extension
-
setExtension
Replace the extension of the given file name with the given extension.- Parameters:
name- the file name to replace the extensionextension- the new extension for the file name- Returns:
- the file name with the given extension
-
extractFileName
-
createReadablePath
-
createReadablePath
-
shortenPath
-
lastPathFragment
-
compare
-
toFile
-
toUrl
Converts a URL or local (possibly relative or space-bearing) path string to aURL, falling back to file semantics when the string is not a valid absolute URI. Replaces the deprecatednew URL(String).- Throws:
MalformedURLException
-
toUrls
-
toUrls
-
reverse
-
calculateConvertFileName
-
createTargetFiles
-
checkFile
- Throws:
FileNotFoundException
-
checkDirectory
- Throws:
FileNotFoundException
-
writePartialFile
public static void writePartialFile(InputStream inputStream, long fileSize, File file) throws IOException - Throws:
IOException
-
generateChecksum
- Throws:
IOException
-
generateChecksum
- Throws:
IOException
-
getLastModified
-
setLastModified
- Throws:
IOException
-
setLastModified
- Throws:
IOException
-
collectFiles
Collects files below the given path with the given extension(s). If path is a directory, the collection recursively descends the directory tree. The extension comparison is case-insensitive- Parameters:
path- the path to collect files belowextensions- the case insensitively compare extensions- Returns:
- the list of files found below the given path and with the given extension(s)
-
collectFiles
-
absolutize
-
findExistingPath
-
recursiveDelete
- Throws:
IOException
-
asLogString
Joins a list into a human-readable, English, uncapped string for log output, e.g.'a',\n'b' and\n'c'. For user-facing dialog text use the localized, capped formatter in the GUI layer instead.
-