public abstract class IoUtil extends Object
Modifier and Type | Method and Description |
---|---|
static void |
copyRecursive(File fromDir,
File toDir)
Copies a complete subdirectory tree using Apache Commons VFS.
|
static void |
copyRecursive(org.apache.commons.vfs.FileSystemManager manager,
org.apache.commons.vfs.FileObject file,
org.apache.commons.vfs.FileObject folder)
Copies a file or a complete subdirectory tree using Apache Commons VFS.
|
static void |
deleteEmptyDirectoryRecursive(File directory)
Deletes an empty directory, including all parent directories that are
also empty, stopping at the first non-empty parent.
|
static void |
deleteRecursive(File file)
Deletes a file or a subdirectory tree.
|
static boolean |
isSameContent(File file,
byte[] digest,
String algorithm)
True if the file has a specific digest.
|
static void |
listRecursiveEndsWith(File file,
String postfix,
Collection<File> files)
Recursively gathers all files with filenames ending with a postfix.
|
static Object |
readJson(File file)
Decodes a JSON UTF-8 file into JVM primitives and collection/map
instances.
|
static List<String> |
readLines(File file)
Reads all lines in a file using UTF-8.
|
static List<String> |
readLines(InputStream stream)
Reads all lines in a stream using UTF-8.
|
static String[] |
separateExtensionFromFilename(String filename)
Returns an array of 2 strings, the first being the filename without its
extension, the second being its extension.
|
static void |
touch(File file)
Updates a file's last-modified timestamp.
|
static void |
unpack(File archiveFile,
File destinationDir,
File workDir)
Unpacks all files in an archive using Apache Commons VFS.
|
static void |
writeJson(File file,
Object object,
boolean expand)
Writes JVM primitives and collection/map instances to a JSON UTF-8 file.
|
static void |
writeLines(File file,
Iterable<String> lines)
Writes lines to a file using UTF-8, overwriting its current contents if
it has any.
|
public static void unpack(File archiveFile, File destinationDir, File workDir) throws IOException
Supported formats: zip, tar.gz/tgz, tar.bz2.
archiveFile
- The archive filedestinationDir
- The destination directoryworkDir
- The work directoryIOException
- In case of an I/O errorpublic static void copyRecursive(org.apache.commons.vfs.FileSystemManager manager, org.apache.commons.vfs.FileObject file, org.apache.commons.vfs.FileObject folder) throws IOException
manager
- The file system managerfile
- The source file or directoryfolder
- The target folderIOException
- In case of an I/O errorpublic static void copyRecursive(File fromDir, File toDir) throws IOException
fromDir
- The source directorytoDir
- The target directoryIOException
- In case of an I/O errorpublic static void deleteEmptyDirectoryRecursive(File directory) throws IOException
directory
- The start directoryIOException
- In case of an I/O errorpublic static void deleteRecursive(File file) throws IOException
file
- The file or directoryIOException
- In case of an I/O errorpublic static void listRecursiveEndsWith(File file, String postfix, Collection<File> files)
file
- The file or directorypostfix
- The required postfixfiles
- The collection to which we will add filespublic static boolean isSameContent(File file, byte[] digest, String algorithm) throws IOException
file
- The filedigest
- The digestalgorithm
- The algorithmIOException
- In case of an I/O errorDigestUtil
public static String[] separateExtensionFromFilename(String filename)
filename
- The filenamepublic static List<String> readLines(File file) throws IOException
Note that this method returns an empty list if the file doesn't exist.
file
- The fileIOException
- In case of an I/O errorpublic static List<String> readLines(InputStream stream) throws IOException
stream
- The streamIOException
- In case of an I/O errorpublic static Object readJson(File file) throws IOException, com.threecrickets.jvm.json.JsonSyntaxError
Note that this method returns null if the file doesn't exist.
file
- The fileIOException
- In case of an I/O errorcom.threecrickets.jvm.json.JsonSyntaxError
- In case of a JSON syntax errorpublic static void writeLines(File file, Iterable<String> lines) throws IOException
Lines end in a newline character.
file
- The filelines
- The linesIOException
- In case of an I/O errorpublic static void writeJson(File file, Object object, boolean expand) throws IOException
file
- The fileobject
- The object (JVM primitives and collection instances)expand
- Whether to expand the JSON with newlines, indents, and spacesIOException
- In case of an I/O errorpublic static void touch(File file) throws IOException
If the file doesn't exist, it is created as an empty file, including necessary parent directories.
file
- The fileIOException
- In case of an I/O errorCopyright © 2011-2016 Three Crickets LLC.