Package net.ssehub.easy.basics.io
Class FileUtils
java.lang.Object
net.ssehub.easy.basics.io.FileUtils
Some file utility methods (may partially be taken from commons.io but this is currently no defined as dependency
of this bundle - see standalone).
- Author:
- Holger Eichelberger
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendToFile(File file, String text) Appendstexttofile.static voidappendToLogFile(String text) Appendstextto "easy-debug.log" in user home.static voidcloseQuietly(Closeable closeable) Closes a closeable quietly, i.e., without exception.static voidCopies a file.static voidcopyToFile(File file, InputStream in) Copies the contents ofinat the current position tofile.static voidcopyToFile(File file, InputStream in, byte[] buffer) Copies the contents ofinat the current position tofile.static voidcreateIfNotExists(File file) Creates a (physical) file if it does not exist.static FilecreateTmpDir(String name) Creates a temporary directory and deletes an existing one if it already exists.static FilecreateTmpDir(String name, boolean deleteIfExists) Creates a temporary directory.static booleanReturns whether the givenuriis a file URI as returned, e.g., by a File.static booleanReturns whether the givenurlis a JAR URL as returned, e.g., by a classloader.static final File[]Lists files infileafter resolvingfileand its contained files.static final FileResolves a file or a symlink.static final File[]Resolves files/symlinks.
-
Field Details
-
IS_WINDOWS
private static final boolean IS_WINDOWS
-
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
isFileURI
Returns whether the givenuriis a file URI as returned, e.g., by a File.- Parameters:
uri- the URI (ignored if null)- Returns:
truefor a file URI,falseelse
-
isFileURL
Returns whether the givenurlis a JAR URL as returned, e.g., by a classloader.- Parameters:
url- the URL (ignored if null)- Returns:
truefor a JAR URL,falseelse
-
copyFile
Copies a file.- Parameters:
target- the target filesource- the source file- Throws:
IOException- in any case of I/O problem, trying to close the involved files before end if possible
-
copyToFile
Copies the contents ofinat the current position tofile. Does not attempt to closein. Uses a default buffer of size 1024.- Parameters:
file- the file to write toin- the input stream- Throws:
IOException- in any case of I/O problem, trying to closefilebefore end if possible
-
copyToFile
Copies the contents ofinat the current position tofile. Does not attempt to closein. Uses a default buffer of size 1024.- Parameters:
file- the file to write toin- the input streambuffer- a copy buffer (if null a default one of size 1024 is used)- Throws:
IOException- in any case of I/O problem, trying to closefilebefore if possible
-
closeQuietly
Closes a closeable quietly, i.e., without exception.- Parameters:
closeable- the closeable
-
createIfNotExists
Creates a (physical) file if it does not exist.- Parameters:
file- the file (may be null, ignored then)
-
createTmpDir
Creates a temporary directory and deletes an existing one if it already exists. Deletion on exit of JVM is enabled for the resulting directory.- Parameters:
name- the name of the directory within the standard temporary folder- Returns:
- the temporary directory
-
createTmpDir
Creates a temporary directory. Deletion on exit of JVM is enabled for the resulting directory.- Parameters:
name- the name of the directory within the standard temporary folderdeleteIfExists- delete an existing one if it already exists- Returns:
- the temporary directory
-
appendToLogFile
Appendstextto "easy-debug.log" in user home. [debugging]- Parameters:
text- the text
-
appendToFile
Appendstexttofile. [debugging]- Parameters:
file- the filetext- the text
-
resolve
Resolves a file or a symlink.- Parameters:
file- the file to be resolved- Returns:
- the resolved file or
fileif it cannot be resolved
-
resolve
Resolves files/symlinks.- Parameters:
files- the files to be resolved, may be null- Returns:
- the resolved files or null
- See Also:
-
listFiles
Lists files infileafter resolvingfileand its contained files.- Parameters:
file- the file to list the files for, may be null- Returns:
- the resolved contained files
- See Also:
-