Package net.ssehub.easy.basics.io
Class FileUtils
- java.lang.Object
-
- net.ssehub.easy.basics.io.FileUtils
-
- Direct Known Subclasses:
FileUtils
public class FileUtils extends java.lang.ObjectSome 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
-
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseQuietly(java.io.Closeable closeable)Closes a closeable quietly, i.e., without exception.static voidcopyFile(java.io.File target, java.io.File source)Copies a file.static voidcopyToFile(java.io.File file, java.io.InputStream in)Copies the contents ofinat the current position tofile.static voidcopyToFile(java.io.File file, java.io.InputStream in, byte[] buffer)Copies the contents ofinat the current position tofile.static voidcreateIfNotExists(java.io.File file)Creates a (physical) file if it does not exist.static java.io.FilecreateTmpDir(java.lang.String name)Creates a temporary directory and deletes an existing one if it already exists.static java.io.FilecreateTmpDir(java.lang.String name, boolean deleteIfExists)Creates a temporary directory.static booleanisFileURI(java.net.URI uri)Returns whether the givenuriis a file URI as returned, e.g., by a File.static booleanisFileURL(java.net.URL url)Returns whether the givenurlis a JAR URL as returned, e.g., by a classloader.
-
-
-
Method Detail
-
isFileURI
public static boolean isFileURI(java.net.URI uri)
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
public static boolean isFileURL(java.net.URL url)
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
public static void copyFile(java.io.File target, java.io.File source) throws java.io.IOExceptionCopies a file.- Parameters:
target- the target filesource- the source file- Throws:
java.io.IOException- in any case of I/O problem, trying to close the involved files before end if possible
-
copyToFile
public static void copyToFile(java.io.File file, java.io.InputStream in) throws java.io.IOExceptionCopies 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:
java.io.IOException- in any case of I/O problem, trying to closefilebefore end if possible
-
copyToFile
public static void copyToFile(java.io.File file, java.io.InputStream in, byte[] buffer) throws java.io.IOExceptionCopies 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:
java.io.IOException- in any case of I/O problem, trying to closefilebefore if possible
-
closeQuietly
public static void closeQuietly(java.io.Closeable closeable)
Closes a closeable quietly, i.e., without exception.- Parameters:
closeable- the closeable
-
createIfNotExists
public static void createIfNotExists(java.io.File file)
Creates a (physical) file if it does not exist.- Parameters:
file- the file (may be null, ignored then)
-
createTmpDir
public static java.io.File createTmpDir(java.lang.String name)
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
public static java.io.File createTmpDir(java.lang.String name, boolean deleteIfExists)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
-
-