public class FileUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFF_SIZE |
static java.lang.String |
DEFAULT_ENCODING |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
baseNameOf(java.lang.String fileName) |
static java.io.File |
buildDirectory(java.io.File rootDir,
java.lang.String relativePath)
Null-safe construction of a file consisting of an absolute root directory, a relative basePath.
|
static java.io.File |
buildFile(java.io.File rootDir,
java.lang.String relativePath,
java.lang.String fileName)
Null-safe construction of a file consisting of an absolute rootDir, a relativePath and a fileName.
|
static java.io.File |
buildFile(java.lang.String relativePath)
Null-safe construction of a file from a relative path.
|
static java.io.File |
buildFile(java.lang.String relativePath,
java.lang.String fileName)
Null-safe construction of a file consisting of a relativePath and a fileName.
|
static void |
checkExistsDirectory(java.io.File dir) |
static void |
checkExistsFile(java.io.File file) |
static void |
copyAll(java.io.File srcDir,
java.io.File dstDir)
Copies the full directory recursively.
|
static void |
copyAll(java.io.File srcDir,
java.io.File dstDir,
java.io.FileFilter filter)
Copies the full directory recursively and applies the given FileFilter
|
static float |
copyAndUnzip(java.io.File zipInFile,
java.io.File unzipOutFile)
Reads the zipped content of zipInFile and writes it unzipped to unzipOutFile.
|
static float |
copyAndZip(java.io.File inFile,
java.io.File zipOutFile)
Reads the content of inFile and writes it zipped to zipOutFile.
|
static int |
copyAsciiResource(java.lang.String resourceName,
java.io.File outFile)
Copies the given resource to the given File and returns the number of lines copied.
|
static int |
copyAsciiResource(java.lang.String resourceName,
java.io.File outFile,
ReplacementMap map)
Same as
copyAsciiResource(String, File) but additionally performs the
replacements defined ReplacementMap in the in all lines being copied. |
static long |
copyAsciiStream(java.io.InputStream in,
java.io.File outFile)
Copies the ASCII content of from a stream into a file.
|
static long |
copyAsciiStream(java.io.InputStream in,
java.io.OutputStream out)
Copies the ASCII content of one stream to another one.
|
static long |
copyBinaryResource(java.lang.String resourceName,
java.io.File outFile) |
static long |
copyBinaryStream(java.io.InputStream in,
java.io.File outFile)
Copies the BINARY content of from a stream into a file.
|
static long |
copyBinaryStream(java.io.InputStream in,
java.io.OutputStream out)
Copies the BINARY content of one stream to another one.
|
static void |
copyFile(java.io.File fileIn,
java.io.File fileOut)
Copies the content of one file to another.
|
static long |
copyStream(java.io.InputStream in,
java.io.OutputStream out)
Copies the content of one stream to another one using an internal buffSize of
DEFAULT_BUFF_SIZE.
|
static long |
copyStream(java.io.InputStream in,
java.io.OutputStream out,
int buffSize)
Copies the content of one stream to another one with the specified buffSize.
|
static int |
countLines(java.io.File file)
Skips through the file content and counts the number of lines in it.
|
static java.lang.String |
cutExtensionFrom(java.lang.String fileName) |
static void |
deleteDir(java.io.File dir)
Removes all files within the given directory and then deletes the directory itself.
|
static void |
deleteDir(java.io.File dir,
boolean isRecursive)
Removes all files within the given directory and then deletes the directory itself.
|
static boolean |
deleteFile(java.io.File file)
Removes the given file/directory and throws an Exception if the deletion failed
|
static int |
deleteFiles(java.io.File dir)
Removes silently all files within the given directory and
returns the number of files that could be deleted successfully.
|
static java.lang.String |
getFileBaseName(java.lang.String fileName)
Cuts off the extension of a filename if it has any
|
static java.lang.String |
getFileTs()
Returns a timestamp string as used for filename creation.
|
static java.io.InputStream |
getResourceAsStream(java.lang.String resourceName)
Tries to open an InputStream to the given resource file.
|
static java.lang.String |
guessMimeTypeFor(java.io.File file)
Tries to guess the mime-type string of a file.
|
static java.io.File[] |
listFiles(java.io.File dir)
Get listing of dir always suitable for iteration over array in for-loops
|
static java.io.File[] |
listFiles(java.io.File dir,
java.io.FileFilter filter)
Get listing of dir always suitable for iteration over array in for-loops
|
static java.io.File[] |
listFiles(java.io.File dir,
java.io.FilenameFilter filter)
Get listing of dir always suitable for iteration over array in for-loops
|
static boolean |
mkdir(java.io.File dir) |
static boolean |
mkdir(java.lang.String dirName) |
static java.io.File |
mkdirs(java.io.File dir)
Creates the full directory tree.
|
static java.io.File |
mkdirs(java.lang.String dirName)
Creates the directory tree.
|
static void |
purgeDir(java.io.File dir)
Removes the whole content of a directory not removing the directory itself.
|
static byte[] |
readBinaryData(java.io.InputStream inStream)
Reads the content of the given stream into a byte array
|
static byte[] |
readBinaryFile(java.io.File file)
Reads the content of the given file into a byte array
|
static byte[] |
readBinaryFile(java.lang.String fileName)
Reads the content of the given file into a byte array
|
static java.util.List<java.io.File> |
readDirectoryTree(java.io.File rootDir)
Reads all directories below rootDir recursively
|
static java.util.List<java.io.File> |
readFileTree(java.io.File rootDir,
java.io.FileFilter filter)
Reads all files under rootDir and its subdirectories recursively.
|
static java.lang.String |
readText(java.io.InputStream inStream) |
static java.lang.String |
readText(java.io.InputStream inStream,
int maxLines) |
static java.lang.String |
readText(java.io.InputStream inStream,
java.lang.String encoding) |
static java.lang.String |
readText(java.io.InputStream inStream,
java.lang.String encoding,
int maxLines)
Returns the text read from the file.
|
static java.lang.String |
readTextFile(java.io.File file)
Reads the content of the given file into a String using UNICODE encoding
|
static java.lang.String |
readTextFile(java.io.File file,
java.lang.String encoding)
Reads the content of the given file into a String using the given encoding.
|
static java.lang.String |
readTextFile(java.lang.String fileName)
Reads the content of the given file into a String
|
static java.lang.String |
readTextResource(java.lang.String resourceName)
Reads the content of the given file into a String
|
static java.io.File |
resolvePath(char varIdentifier,
java.lang.String path) |
static java.io.File |
resolvePath(java.lang.String path) |
static void |
setLastModified(java.io.File file,
long time)
Updates the modification timestamp on a File.
|
static java.lang.String |
toRelativePath(java.io.File rootPath,
java.io.File absolutePath) |
static void |
touch(java.io.File file)
Updates the modification timestamp on a File.
|
static void |
touch(java.io.File file,
long time)
Updates the modification timestamp on a File.
|
static java.lang.String |
toUnixPathName(java.io.File file)
Converts all backslashes to slashes in a file-pathname
|
static java.lang.String |
toUnixPathName(java.lang.String p)
Converts all backslashes to slashes in a file-pathname
|
static java.lang.String |
toValidFileName(java.lang.String str)
Converts the String to a valid file name.
|
static boolean |
truncate(java.io.File file)
Clears the content of the given File
|
static <E> E |
unzipObject(byte[] data)
Deserializes and instantiates an Object from data in GZIP format.
|
static void |
writeBinaryFile(java.io.File file,
byte[] data)
Writes the content of the given byte array to the file
|
static void |
writeBinaryFile(java.lang.String fileName,
byte[] data)
Writes the content of the given byte array to the file
|
static int |
writeText(java.io.OutputStream outStream,
java.lang.String text)
Writes the given text (may be multi-line) to the outStream with the default
platform encoding.
|
static int |
writeText(java.io.OutputStream outStream,
java.lang.String text,
java.lang.String encoding)
Writes the given text (may be multi-line) to the outStream with the given encoding.
|
static int |
writeTextFile(java.io.File file,
java.lang.String text)
Writes the given String into the given File using UNICODE encoding
|
static int |
writeTextFile(java.io.File file,
java.lang.String text,
java.lang.String encoding)
Writes the given String into the given File using the given encoding.
|
static byte[] |
zipObject(java.lang.Object arg)
Serializes the Object and zips the data in GZIP format.
|
public static final java.lang.String DEFAULT_ENCODING
public static final int DEFAULT_BUFF_SIZE
public static java.io.File buildFile(java.io.File rootDir, java.lang.String relativePath, java.lang.String fileName)
public static java.lang.String baseNameOf(java.lang.String fileName)
public static java.io.File buildFile(java.lang.String relativePath, java.lang.String fileName)
public static java.io.File buildFile(java.lang.String relativePath)
public static java.io.File buildDirectory(java.io.File rootDir, java.lang.String relativePath)
public static java.lang.String cutExtensionFrom(java.lang.String fileName)
public static java.io.InputStream getResourceAsStream(java.lang.String resourceName) throws java.io.IOException
java.io.IOException
public static int copyAsciiResource(java.lang.String resourceName, java.io.File outFile) throws java.io.IOException
java.io.IOException
public static int copyAsciiResource(java.lang.String resourceName, java.io.File outFile, ReplacementMap map) throws java.io.IOException
copyAsciiResource(String, File)
but additionally performs the
replacements defined ReplacementMap
in the in all lines being copied.java.io.IOException
public static long copyBinaryResource(java.lang.String resourceName, java.io.File outFile) throws java.io.IOException
java.io.IOException
public static byte[] readBinaryFile(java.lang.String fileName) throws java.io.IOException
java.io.IOException
public static byte[] readBinaryFile(java.io.File file) throws java.io.IOException
java.io.IOException
public static byte[] readBinaryData(java.io.InputStream inStream) throws java.io.IOException
java.io.IOException
public static void writeBinaryFile(java.lang.String fileName, byte[] data) throws java.io.IOException
java.io.IOException
public static void writeBinaryFile(java.io.File file, byte[] data) throws java.io.IOException
java.io.IOException
public static java.lang.String readTextFile(java.lang.String fileName) throws java.io.IOException
java.io.IOException
public static java.lang.String readTextFile(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String readTextFile(java.io.File file, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static java.lang.String readTextResource(java.lang.String resourceName) throws java.io.IOException
java.io.IOException
public static java.lang.String readText(java.io.InputStream inStream) throws java.io.IOException
java.io.IOException
public static java.lang.String readText(java.io.InputStream inStream, int maxLines) throws java.io.IOException
java.io.IOException
public static java.lang.String readText(java.io.InputStream inStream, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static java.lang.String readText(java.io.InputStream inStream, java.lang.String encoding, int maxLines) throws java.io.IOException
java.io.IOException
public static int countLines(java.io.File file) throws java.io.IOException
java.io.IOException
public static int writeTextFile(java.io.File file, java.lang.String text) throws java.io.IOException
java.io.IOException
public static int writeTextFile(java.io.File file, java.lang.String text, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static int writeText(java.io.OutputStream outStream, java.lang.String text) throws java.io.IOException
java.io.IOException
public static int writeText(java.io.OutputStream outStream, java.lang.String text, java.lang.String encoding) throws java.io.IOException
java.io.IOException
public static java.lang.String getFileTs()
public static java.lang.String getFileBaseName(java.lang.String fileName)
public static java.lang.String toValidFileName(java.lang.String str)
public static java.lang.String toUnixPathName(java.lang.String p)
public static java.lang.String toUnixPathName(java.io.File file)
public static java.lang.String toRelativePath(java.io.File rootPath, java.io.File absolutePath)
public static void copyFile(java.io.File fileIn, java.io.File fileOut) throws java.io.IOException
java.io.IOException
public static long copyBinaryStream(java.io.InputStream in, java.io.File outFile) throws java.io.IOException
java.io.IOException
public static long copyBinaryStream(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static long copyAsciiStream(java.io.InputStream in, java.io.File outFile) throws java.io.IOException
java.io.IOException
public static long copyAsciiStream(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static long copyStream(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
java.io.IOException
public static long copyStream(java.io.InputStream in, java.io.OutputStream out, int buffSize) throws java.io.IOException
java.io.IOException
public static float copyAndZip(java.io.File inFile, java.io.File zipOutFile) throws java.io.IOException
java.io.IOException
copyAndUnzip(File, File)
public static float copyAndUnzip(java.io.File zipInFile, java.io.File unzipOutFile) throws java.io.IOException
java.io.IOException
copyAndZip(File, File)
public static byte[] zipObject(java.lang.Object arg)
unzipObject(byte[])
public static <E> E unzipObject(byte[] data) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
zipObject(Object)
public static java.util.List<java.io.File> readDirectoryTree(java.io.File rootDir)
public static java.util.List<java.io.File> readFileTree(java.io.File rootDir, java.io.FileFilter filter)
public static boolean mkdir(java.lang.String dirName) throws java.lang.Exception
java.lang.Exception
public static boolean mkdir(java.io.File dir) throws java.lang.Exception
java.lang.Exception
public static java.io.File mkdirs(java.lang.String dirName) throws java.lang.Exception
java.lang.Exception
public static java.io.File mkdirs(java.io.File dir) throws java.lang.Exception
java.lang.Exception
public static void purgeDir(java.io.File dir) throws java.lang.Exception
java.lang.Exception
public static void deleteDir(java.io.File dir, boolean isRecursive) throws java.lang.Exception
isRecursive
- delete the whole directory recursivelyjava.lang.Exception
public static int deleteFiles(java.io.File dir)
public static void deleteDir(java.io.File dir) throws java.lang.Exception
java.lang.Exception
public static boolean deleteFile(java.io.File file) throws java.lang.Exception
java.lang.Exception
public static void checkExistsFile(java.io.File file) throws java.lang.Exception
java.lang.Exception
public static void checkExistsDirectory(java.io.File dir) throws java.lang.Exception
java.lang.Exception
public static java.io.File[] listFiles(java.io.File dir)
dir
- public static java.io.File[] listFiles(java.io.File dir, java.io.FileFilter filter)
dir
- filter
- public static java.io.File[] listFiles(java.io.File dir, java.io.FilenameFilter filter)
dir
- filter
- public static boolean truncate(java.io.File file) throws java.lang.Exception
java.lang.Exception
public static void copyAll(java.io.File srcDir, java.io.File dstDir) throws java.lang.Exception
java.lang.Exception
public static void copyAll(java.io.File srcDir, java.io.File dstDir, java.io.FileFilter filter) throws java.lang.Exception
java.lang.Exception
public static void touch(java.io.File file) throws java.lang.Exception
java.lang.Exception
public static void touch(java.io.File file, long time) throws java.lang.Exception
java.lang.Exception
public static void setLastModified(java.io.File file, long time) throws java.lang.Exception
java.lang.Exception
- if the file does not exist.public static java.lang.String guessMimeTypeFor(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.io.File resolvePath(java.lang.String path)
public static java.io.File resolvePath(char varIdentifier, java.lang.String path)
Copyright © 2014 EsprIT-Systems. All Rights Reserved.