public class FileHelper extends Object
| Constructor and Description |
|---|
FileHelper() |
| Modifier and Type | Method and Description |
|---|---|
protected static long |
computeLastModification(File file) |
protected static long |
computeLastModificationDateRecursive(File file) |
static void |
copy(InputStream input,
OutputStream output)
Copy a
InputStream to an OutputStream using a buffer size of 2048 |
static void |
copy(InputStream input,
OutputStream output,
int bufferSize)
Copy a
InputStream to an OutputStream |
static File |
createTempFile()
Creates a temporary file that will be deleted on JVM exit
|
static File |
createTempFolder()
Creates a temporary folder
|
static File |
createTempFolder(String prefix)
Creates a temporary folder
|
static void |
deleteFolder(File folder)
Deletes a folder recursively
|
static void |
deleteFolderOnExit(File folder)
Requests that the directory denoted by this abstract pathname be deleted recursively when the virtual machine terminates
|
static File |
extractResourceToTempFile(Class<?> clazz,
String resourceName)
Extract a resource and copy it to a a temporary file
|
static File |
getClassLoaderResourceAsFile(ClassLoader classLoader,
String resourceName) |
static long |
getLastModificationDateRecursive(File file)
Computes the last modification date of a file or a folder recursively
|
static String |
readClassLoaderResource(ClassLoader classLoader,
String resourceName)
Reads a classloader resource using UTF8 charset
|
static byte[] |
readClassLoaderResourceAsByteArray(ClassLoader classLoader,
String resourceName)
Reads a classloader resource and returns its content as byte array
|
static String |
readResource(Class<?> clazz,
String resourceName)
Reads a resource using UTF8 charset
|
static byte[] |
readResourceAsByteArray(Class<?> clazz,
String resourceName)
Reads a resource and returns its content as byte array
|
static String |
readStream(InputStream is)
Reads the stream provided as argument using UTF8 charset
|
static void |
unzip(byte[] bytes,
File target)
Extracts the zip provided as byte array to the target folder provided as argument
|
static void |
unzip(File zipFile,
File target)
Extracts the zip file to the target folder provided as argument
|
static void |
unzip(InputStream stream,
File target)
Extracts the zip provided as stream to the target folder provided as argument
|
static byte[] |
zip(File directory)
Create a zip file of the directory denoted by the
File passed as argument |
static void |
zip(File directory,
File target)
Create a zip file of the directory denoted by the
File passed as argument |
static void |
zip(File directory,
OutputStream out)
Create a zip file of the directory denoted by the
File passed as argument |
public static File createTempFile() throws IOException
File of the temporary fileIOExceptionpublic static File createTempFolder() throws IOException
IOExceptionpublic static File createTempFolder(String prefix) throws IOException
prefix - the prefix string to be used in generating the folder's nameFile of the temporary folderIOExceptionpublic static void deleteFolder(File folder)
folder - the File to be deletedpublic static void deleteFolderOnExit(File folder)
folder - the File to be deletedpublic static final long getLastModificationDateRecursive(File file)
file - protected static final long computeLastModification(File file)
protected static final long computeLastModificationDateRecursive(File file)
public static void unzip(File zipFile, File target) throws IOException
zipFile - the zip file to be extractedtarget - the target folder to extract toIOExceptionpublic static void unzip(byte[] bytes,
File target)
throws IOException
bytes - the byte array of the zip to be extractedtarget - the target folder to extract toIOExceptionpublic static void unzip(InputStream stream, File target) throws IOException
stream - the InputStream of the zip to be extractedtarget - the target folder to extract toIOExceptionpublic static final void zip(File directory, File target) throws IOException
File passed as argumentdirectory - the directory to be zippedtarget - the path to the target zip fileIOExceptionpublic static final void zip(File directory, OutputStream out) throws IOException
File passed as argumentdirectory - the directory to be zippedout - the output stream of the target zip fileIOExceptionpublic static final byte[] zip(File directory) throws IOException
File passed as argumentdirectory - the directory to be zippedIOExceptionpublic static String readStream(InputStream is)
is - the stream to be readpublic static String readResource(Class<?> clazz, String resourceName)
clazz - the class the resource is associated withresourceName - the name of the resourcepublic static String readClassLoaderResource(ClassLoader classLoader, String resourceName)
classLoader - the classloader to access the resourceresourceName - the name of the resourcepublic static byte[] readResourceAsByteArray(Class<?> clazz, String resourceName) throws IOException
clazz - the class the resource is associated withresourceName - the name of the resourceIOExceptionpublic static byte[] readClassLoaderResourceAsByteArray(ClassLoader classLoader, String resourceName) throws IOException
classLoader - the classloader to access the resourceresourceName - the name of the resourceIOExceptionpublic static File getClassLoaderResourceAsFile(ClassLoader classLoader, String resourceName)
classLoader - the classloader to access the resourceresourceName - the name of the resourceFilepublic static File extractResourceToTempFile(Class<?> clazz, String resourceName) throws IOException
clazz - the class the resource is associated withresourceName - the name of the resourceFileIOExceptionpublic static void copy(InputStream input, OutputStream output) throws IOException
InputStream to an OutputStream using a buffer size of 2048input - the InputStream to be readoutput - the target OutputStreamIOExceptionpublic static void copy(InputStream input, OutputStream output, int bufferSize) throws IOException
InputStream to an OutputStreaminput - the InputStream to be readoutput - the target OutputStreambufferSize - the buffersize to be usedIOExceptionCopyright © 2019. All rights reserved.