public class FileUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static java.util.LinkedList<java.io.File> |
pendingDeletes |
| Modifier and Type | Method and Description |
|---|---|
static void |
appendTo(java.io.File fileToAppendTo,
java.io.File fileToAppendFrom) |
static java.io.File |
assertReadable(java.io.File f)
Test file exists and is readable.
|
static boolean |
copyFile(java.io.File src,
java.io.File dest)
Copy the src file to the destination.
|
static boolean |
copyFile(java.io.File src,
java.io.File dest,
long extent)
Copy up to extent bytes of the source file to the destination.
|
static boolean |
copyFile(java.io.File src,
java.io.File dest,
long extent,
boolean overwrite)
Copy up to extent bytes of the source file to the destination
|
static void |
deleteSoonerOrLater(java.io.File fileToDelete)
Delete the file now -- but in the event of failure, keep trying
in the future.
|
static java.io.File |
ensureWriteableDirectory(java.io.File dir)
Ensure writeable directory.
|
static java.util.List<java.io.File> |
ensureWriteableDirectory(java.util.List<java.io.File> dirs)
Ensure writeable directories.
|
static java.io.File |
ensureWriteableDirectory(java.lang.String dir)
Ensure writeable directory.
|
static org.apache.commons.lang.math.LongRange |
expandRange(org.apache.commons.lang.math.LongRange range1,
org.apache.commons.lang.math.LongRange range2) |
static java.io.File[] |
getFilesWithPrefix(java.io.File dir,
java.lang.String prefix)
Get a list of all files in directory that have passed prefix.
|
static org.apache.commons.io.filefilter.IOFileFilter |
getRegexFileFilter(java.lang.String regex)
Get a @link java.io.FileFilter that filters files based on a regular
expression.
|
static boolean |
isReadableWithExtensionAndMagic(java.io.File f,
java.lang.String uncompressedExtension,
java.lang.String magic) |
static java.util.Properties |
loadProperties(java.io.File file)
Load Properties instance from a File
|
static java.io.File |
maybeRelative(java.io.File context,
java.lang.String path)
Turn path into a File, relative to context (which may be ignored
if path is absolute).
|
static boolean |
moveAsideIfExists(java.io.File file) |
static org.apache.commons.lang.math.LongRange |
pagedLines(java.io.File file,
long position,
int signedDesiredLongCount,
java.util.List<java.lang.String> lines) |
static org.apache.commons.lang.math.LongRange |
pagedLines(java.io.File file,
long position,
int signedDesiredLineCount,
java.util.List<java.lang.String> lines,
int lineEstimate)
Retrieve a number of lines from the file around the given
position, as when paging forward or backward through a file.
|
static long |
readFullyToFile(java.io.InputStream is,
java.io.File toFile)
Read the entire stream to EOF into the passed file.
|
static void |
storeProperties(java.util.Properties p,
java.io.File file)
Store Properties instance to a File
|
static java.io.File |
tryToCanonicalize(java.io.File file) |
protected static void |
workaroundCopyFile(java.io.File src,
java.io.File dest) |
public static boolean copyFile(java.io.File src,
java.io.File dest)
throws java.io.FileNotFoundException,
java.io.IOException
src - dest - java.io.FileNotFoundExceptionjava.io.IOExceptionpublic static boolean copyFile(java.io.File src,
java.io.File dest,
long extent)
throws java.io.FileNotFoundException,
java.io.IOException
src - dest - extent - Maximum number of bytes to copyjava.io.FileNotFoundExceptionjava.io.IOExceptionpublic static boolean copyFile(java.io.File src,
java.io.File dest,
long extent,
boolean overwrite)
throws java.io.FileNotFoundException,
java.io.IOException
src - dest - extent - Maximum number of bytes to copyoverwrite - If target file already exits, and this parameter is
true, overwrite target file (We do this by first deleting the target
file before we begin the copy).java.io.FileNotFoundExceptionjava.io.IOExceptionprotected static void workaroundCopyFile(java.io.File src,
java.io.File dest)
throws java.io.IOException
java.io.IOExceptionpublic static java.io.File[] getFilesWithPrefix(java.io.File dir,
java.lang.String prefix)
dir - Dir to look in.prefix - Basename of files to look for. Compare is case insensitive.public static org.apache.commons.io.filefilter.IOFileFilter getRegexFileFilter(java.lang.String regex)
regex - the regular expression the files must match.public static java.io.File assertReadable(java.io.File f)
throws java.io.FileNotFoundException
f - File to test.java.io.FileNotFoundException - If file does not exist or is not unreadable.public static boolean isReadableWithExtensionAndMagic(java.io.File f,
java.lang.String uncompressedExtension,
java.lang.String magic)
throws java.io.IOException
f - File to test.java.io.IOException - If file not readable or other problem.public static java.io.File maybeRelative(java.io.File context,
java.lang.String path)
context - File context if path is relativepath - String path to make into a Filepublic static java.util.Properties loadProperties(java.io.File file)
throws java.io.IOException
file - java.io.IOExceptionpublic static void storeProperties(java.util.Properties p,
java.io.File file)
throws java.io.IOException
p - file - destination Filejava.io.IOExceptionpublic static boolean moveAsideIfExists(java.io.File file)
throws java.io.IOException
java.io.IOExceptionpublic static org.apache.commons.lang.math.LongRange pagedLines(java.io.File file,
long position,
int signedDesiredLineCount,
java.util.List<java.lang.String> lines,
int lineEstimate)
throws java.io.IOException
file - File to retrieve linesposition - offset to anchor linessignedDesiredLineCount - lines requested; if negative,
want this number of lines ending with a line containing
the position; if positive, want this number of lines,
all starting at or after position.lines - ListlineEstimate - int estimate of line size, 0 means use default
of 128java.io.IOExceptionpublic static org.apache.commons.lang.math.LongRange expandRange(org.apache.commons.lang.math.LongRange range1,
org.apache.commons.lang.math.LongRange range2)
public static org.apache.commons.lang.math.LongRange pagedLines(java.io.File file,
long position,
int signedDesiredLongCount,
java.util.List<java.lang.String> lines)
throws java.io.IOException
java.io.IOExceptionpublic static void deleteSoonerOrLater(java.io.File fileToDelete)
fileToDelete - public static long readFullyToFile(java.io.InputStream is,
java.io.File toFile)
throws java.io.IOException
is when done or if an exception.is - Stream to read.toFile - File to write to.java.io.IOExceptionpublic static java.io.File ensureWriteableDirectory(java.lang.String dir)
throws java.io.IOException
dir - Directory to test for exitence and is writeable.dir.java.io.IOException - If passed directory does not exist and is not
createable, or directory is not writeable or is not a directory.public static java.util.List<java.io.File> ensureWriteableDirectory(java.util.List<java.io.File> dirs)
throws java.io.IOException
dirs - List of Files to test.dirs.java.io.IOException - If passed directory does not exist and is not
createable, or directory is not writeable or is not a directory.public static java.io.File ensureWriteableDirectory(java.io.File dir)
throws java.io.IOException
dir - Directory to test for exitence and is writeable.dir.java.io.IOException - If passed directory does not exist and is not
createable, or directory is not writeable or is not a directory.public static java.io.File tryToCanonicalize(java.io.File file)
public static void appendTo(java.io.File fileToAppendTo,
java.io.File fileToAppendFrom)
throws java.io.IOException
java.io.IOExceptionCopyright © 2019 The International Internet Preservation Consortium. All Rights Reserved.