java.lang.Object
org.tentackle.common.FileHelper
Helper methods for file handling.
- Author:
- harald
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidCopies a file.static intcopyDirectory(File srcDir, File dstDir, boolean recursive, FileFilter filter) Copies all files from one directory to another.static InputStreamcreateInputStream(Class<?> caller, String name) Creates an input stream from a resource.static byte[]Downloads data from a URL into memory.static EncryptedPropertiesloadProperties(String name) Loads properties.
Tries to load from filesystem first, then from classpath.static EncryptedPropertiesloadProperties(String name, boolean asResource) Loads properties from a resource.static voidremoveDirectory(String name) Removes a directory and all its contents recursively.static voidUnzips a zip file.
-
Method Details
-
createInputStream
Creates an input stream from a resource.- Parameters:
caller- the caller class, null to determine viaStackWalkername- the resource name- Returns:
- the input stream
- Throws:
IOException- if reading the resources failedFileNotFoundException- if no such resources found
-
loadProperties
public static EncryptedProperties loadProperties(String name, boolean asResource) throws IOException Loads properties from a resource.- Parameters:
name- the properties name, null if return empty propertiesasResource- true if load from the classpath, false if from filesystem- Returns:
- the properties, empty if name is null
- Throws:
IOException- if reading the property file failedFileNotFoundException- if no properties found
-
loadProperties
Loads properties.
Tries to load from filesystem first, then from classpath.- Parameters:
name- the properties name, null if return empty properties- Returns:
- the properties, empty if filename is null
- Throws:
IOException- if reading the property file failedFileNotFoundException- if no properties found
-
copy
Copies a file.- Parameters:
source- the source filedest- the destination file- Throws:
IOException- if some I/O error
-
copyDirectory
public static int copyDirectory(File srcDir, File dstDir, boolean recursive, FileFilter filter) throws IOException Copies all files from one directory to another.- Parameters:
srcDir- the source directorydstDir- the destination directoryrecursive- true if copy also subdirectoriesfilter- optional file filter, null if none- Returns:
- number of files copied
- Throws:
IOException- if copy failed
-
download
Downloads data from a URL into memory.- Parameters:
url- the URL- Returns:
- the data as bytes
- Throws:
IOException- if failed
-
removeDirectory
Removes a directory and all its contents recursively.- Parameters:
name- the directory name- Throws:
IOException- if failed
-
unzip
public static void unzip(File zipFile, File destDir, Consumer<File> fileConsumer) throws IOException Unzips a zip file.- Parameters:
zipFile- the zip filedestDir- the destination directoryfileConsumer- optional consumer to receive the file being unzipped- Throws:
IOException- if failed
-