public final class FileUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
FileUtils.StringsIterator |
Modifier and Type | Field and Description |
---|---|
private static java.util.regex.Pattern |
backslashbackslash |
private static char |
CR |
private static int |
DEFAULT_BUFFER_SIZE |
private static java.util.regex.Pattern |
escaped_backslash |
private static java.util.regex.Pattern |
escaped_equal |
private static java.util.regex.Pattern |
escaped_newline |
private static char |
LF |
private static java.util.regex.Pattern |
unescaped_equal |
Constructor and Description |
---|
FileUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
checkCharset(java.io.File file,
java.lang.String givenCharset,
boolean concurrent)
Because the checking of very large files for their charset may take some time, we do this concurrently in this method
This method does not return anything but it logs an info line if the charset is a good choice
and it logs a warning line if the choice was bad.
|
static void |
copy(byte[] source,
java.io.File dest) |
static void |
copy(byte[] source,
java.io.OutputStream dest) |
static void |
copy(java.io.File source,
java.io.OutputStream dest)
Copies a File to an OutputStream.
|
static void |
copy(java.io.InputStream source,
java.io.File dest) |
static void |
copy(java.io.InputStream source,
java.io.File dest,
long count)
Copies an InputStream to a File.
|
static long |
copy(java.io.InputStream source,
java.io.OutputStream dest) |
static long |
copy(java.io.InputStream source,
java.io.OutputStream dest,
long count)
Copies an InputStream to an OutputStream.
|
static int |
copy(java.io.InputStream source,
java.io.Writer dest) |
static int |
copy(java.io.InputStream source,
java.io.Writer dest,
java.nio.charset.Charset inputCharset) |
static int |
copy(java.io.Reader source,
java.io.Writer dest) |
static int |
copy(java.lang.String source,
java.io.Writer dest) |
static void |
copyRange(java.io.File source,
java.io.OutputStream dest,
int start)
Copies a part of a File to an OutputStream.
|
static java.io.File |
createTempFile(java.lang.Class<?> classObj,
java.lang.String name)
Creates a temp file in the default system tmp directory (System property ""java.io.tmpdir"")
with a name constructed by combination of class name and name.
|
static void |
deletedelete(java.io.File path)
delete files and directories if a directory is not empty, delete also everything inside because
deletion sometimes fails on windows, there is also a windows exec included
|
static java.util.Set<java.lang.String> |
detectCharset(java.io.File file)
auto-detect the charset of a file
used code from http://jchardet.sourceforge.net/;
see also: http://www-archive.mozilla.org/projects/intl/chardet.html
|
private static void |
forceMove(java.io.File from,
java.io.File to) |
static java.util.List<java.lang.String> |
getDirListing(java.io.File dir)
Read content of a directory into a String array of file names.
|
static java.util.List<java.lang.String> |
getDirListing(java.io.File dir,
java.lang.String filter)
Read content of a directory into a String array of file names.
|
static java.util.List<java.lang.String> |
getDirListing(java.lang.String dirname)
Read content of a directory into a String array of file names.
|
static java.util.List<java.lang.String> |
getDirListing(java.lang.String dirname,
java.lang.String filter)
Read content of a directory into a String array of file names.
|
static java.util.ArrayList<java.io.File> |
getDirsRecursive(java.io.File dir,
java.lang.String notdir) |
private static java.util.ArrayList<java.io.File> |
getDirsRecursive(java.io.File dir,
java.lang.String notdir,
boolean excludeDotfiles)
Returns a List of all dirs and subdirs as File Objects Warning: untested
|
static java.util.List<java.io.File> |
getFilesRecursive(java.io.File sourceDir,
java.lang.String notdir,
java.io.FilenameFilter fileNameFilter) |
static java.util.ArrayList<java.lang.String> |
getListArray(java.io.File listFile)
Read lines of a file into an ArrayList.
|
static java.lang.String |
getListString(java.io.File listFile,
boolean withcomments)
Read lines of a text file into a String, optionally ignoring comments.
|
static boolean |
isInDirectory(java.io.File file,
java.io.File directory)
Checks if a certain file is in a given directory.
|
static java.util.HashSet<java.lang.String> |
loadList(java.io.File file) |
static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String> |
loadMap(java.io.File f) |
static java.util.concurrent.ConcurrentHashMap<java.lang.String,byte[]> |
loadMapB(java.io.File f) |
static byte[] |
read(java.io.File source) |
static byte[] |
read(java.io.InputStream source)
Read fully source stream and close it.
|
static byte[] |
read(java.io.InputStream source,
int count) |
static void |
saveMap(java.io.File file,
java.util.Map<java.lang.String,java.lang.String> props,
java.lang.String comment) |
static void |
saveMapB(java.io.File file,
java.util.Map<java.lang.String,byte[]> props,
java.lang.String comment) |
static java.util.Iterator<java.lang.String> |
strings(byte[] a) |
static java.util.Map<java.lang.String,java.lang.String> |
table(byte[] a) |
static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String> |
table(java.util.Iterator<java.lang.String> li) |
static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String> |
table(java.io.Reader r) |
static byte[] |
uncompressGZipArray(byte[] source)
This function determines if a byte array is gzip compressed and uncompress it
|
private static boolean |
writeList(java.io.File listFile,
java.lang.String out)
Write a String to a file (used for string representation of lists).
|
static boolean |
writeList(java.io.File listFile,
java.lang.String[] list)
Write elements of an Array of Strings to a file (one element per line).
|
private static final int DEFAULT_BUFFER_SIZE
private static final java.util.regex.Pattern backslashbackslash
private static final java.util.regex.Pattern unescaped_equal
private static final java.util.regex.Pattern escaped_equal
private static final java.util.regex.Pattern escaped_newline
private static final java.util.regex.Pattern escaped_backslash
private static final char LF
private static final char CR
public static long copy(java.io.InputStream source, java.io.OutputStream dest) throws java.io.IOException
java.io.IOException
public static long copy(java.io.InputStream source, java.io.OutputStream dest, long count) throws java.io.IOException
source
- InputStreamdest
- OutputStreamcount
- the total amount of bytes to copy (-1 for all, else must be greater than zero)java.io.IOException
copy(InputStream source, File dest)
,
copyRange(File source, OutputStream dest, int start)
,
copy(File source, OutputStream dest)
,
#copy(File source, File dest)
public static int copy(java.io.InputStream source, java.io.Writer dest) throws java.io.IOException
java.io.IOException
public static int copy(java.io.InputStream source, java.io.Writer dest, java.nio.charset.Charset inputCharset) throws java.io.IOException
java.io.IOException
public static int copy(java.lang.String source, java.io.Writer dest) throws java.io.IOException
java.io.IOException
public static int copy(java.io.Reader source, java.io.Writer dest) throws java.io.IOException
java.io.IOException
public static void copy(java.io.InputStream source, java.io.File dest) throws java.io.IOException
java.io.IOException
public static void copy(java.io.InputStream source, java.io.File dest, long count) throws java.io.IOException
source
- InputStreamdest
- Filecount
- the amount of bytes to copyjava.io.IOException
copy(InputStream source, OutputStream dest)
,
copyRange(File source, OutputStream dest, int start)
,
copy(File source, OutputStream dest)
,
#copy(File source, File dest)
public static void copyRange(java.io.File source, java.io.OutputStream dest, int start) throws java.io.IOException
source
- Filedest
- OutputStreamstart
- Number of bytes to skip from the beginning of the Filejava.io.IOException
copy(InputStream source, OutputStream dest)
,
copy(InputStream source, File dest)
,
copy(File source, OutputStream dest)
,
#copy(File source, File dest)
public static void copy(java.io.File source, java.io.OutputStream dest) throws java.io.IOException
source
- Filedest
- OutputStreamjava.io.IOException
copy(InputStream source, OutputStream dest)
,
copy(InputStream source, File dest)
,
copyRange(File source, OutputStream dest, int start)
,
#copy(File source, File dest)
public static void copy(byte[] source, java.io.OutputStream dest) throws java.io.IOException
java.io.IOException
public static void copy(byte[] source, java.io.File dest) throws java.io.IOException
java.io.IOException
public static byte[] read(java.io.InputStream source) throws java.io.IOException
source
- must not be nulljava.io.IOException
- when a read/write error occuredpublic static byte[] read(java.io.InputStream source, int count) throws java.io.IOException
java.io.IOException
public static byte[] read(java.io.File source) throws java.io.IOException
java.io.IOException
public static byte[] uncompressGZipArray(byte[] source) throws java.io.IOException
source
- properly gzip compressed byte arrayjava.io.IOException
public static java.util.HashSet<java.lang.String> loadList(java.io.File file)
public static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String> loadMap(java.io.File f)
public static java.util.concurrent.ConcurrentHashMap<java.lang.String,byte[]> loadMapB(java.io.File f)
public static void saveMap(java.io.File file, java.util.Map<java.lang.String,java.lang.String> props, java.lang.String comment)
public static void saveMapB(java.io.File file, java.util.Map<java.lang.String,byte[]> props, java.lang.String comment)
public static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String> table(java.io.Reader r)
public static java.util.concurrent.ConcurrentHashMap<java.lang.String,java.lang.String> table(java.util.Iterator<java.lang.String> li)
public static java.util.Map<java.lang.String,java.lang.String> table(byte[] a)
public static java.util.Iterator<java.lang.String> strings(byte[] a)
public static java.util.ArrayList<java.lang.String> getListArray(java.io.File listFile)
listFile
- the fileprivate static boolean writeList(java.io.File listFile, java.lang.String out)
listFile
- the file to write toout
- the String to writetrue
if successful, false
otherwisepublic static java.lang.String getListString(java.io.File listFile, boolean withcomments)
listFile
- the File to read from.withcomments
- If false
ignore lines starting with '#'.public static java.util.List<java.lang.String> getDirListing(java.lang.String dirname)
dirname
- The directory to get the file listing from. If it doesn't exist yet, it will be created.public static java.util.List<java.lang.String> getDirListing(java.lang.String dirname, java.lang.String filter)
dirname
- The directory to get the file listing from. If it doesn't exist yet, it will be created.filter
- String which contains a regular expression which has to be matched by file names in order
to appear in returned array. All file names will be returned if filter is null.public static java.util.List<java.lang.String> getDirListing(java.io.File dir)
dir
- The directory to get the file listing from. If it doesn't exist yet, it will be created.public static java.util.List<java.lang.String> getDirListing(java.io.File dir, java.lang.String filter)
dir
- The directory to get the file listing from. If it doesn't exist yet, it will be created.filter
- String which contains a regular expression which has to be matched by file names in order
to appear in returned array. All file names will be returned if filter is null.public static java.util.ArrayList<java.io.File> getDirsRecursive(java.io.File dir, java.lang.String notdir)
public static java.util.List<java.io.File> getFilesRecursive(java.io.File sourceDir, java.lang.String notdir, java.io.FilenameFilter fileNameFilter)
sourceDir
- source directory. Must be not null.notdir
- name of dir to exlcude. Can be nullfileNameFilter
- filter to apply on file names. Can be null.private static java.util.ArrayList<java.io.File> getDirsRecursive(java.io.File dir, java.lang.String notdir, boolean excludeDotfiles)
public static boolean writeList(java.io.File listFile, java.lang.String[] list)
listFile
- the file to write tolist
- the Array to writetrue
if successful, false
otherwiseprivate static void forceMove(java.io.File from, java.io.File to) throws java.io.IOException
from
- to
- java.io.IOException
public static final java.io.File createTempFile(java.lang.Class<?> classObj, java.lang.String name) throws java.io.IOException
classObj
- name is used as prefixname
- java.io.IOException
public static void deletedelete(java.io.File path)
path
- public static boolean isInDirectory(java.io.File file, java.io.File directory)
file
- the file to checkdirectory
- the directory which must contain the filepublic static java.util.Set<java.lang.String> detectCharset(java.io.File file) throws java.io.IOException
file
- java.io.IOException
public static void checkCharset(java.io.File file, java.lang.String givenCharset, boolean concurrent)
file
- the file to be checkedgivenCharset
- the charset that we consider to be validconcurrent
- if this shall run concurrently