public class FileUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static LinkedList<File> |
pendingDeletes |
| Modifier and Type | Method and Description |
|---|---|
static void |
appendTo(File fileToAppendTo,
File fileToAppendFrom) |
static File |
assertReadable(File f)
Test file exists and is readable.
|
static boolean |
copyFile(File src,
File dest)
Copy the src file to the destination.
|
static boolean |
copyFile(File src,
File dest,
long extent)
Copy up to extent bytes of the source file to the destination.
|
static boolean |
copyFile(File src,
File dest,
long extent,
boolean overwrite)
Copy up to extent bytes of the source file to the destination
|
static void |
deleteSoonerOrLater(File fileToDelete)
Delete the file now -- but in the event of failure, keep trying
in the future.
|
static File |
ensureWriteableDirectory(File dir)
Ensure writeable directory.
|
static List<File> |
ensureWriteableDirectory(List<File> dirs)
Ensure writeable directories.
|
static File |
ensureWriteableDirectory(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 File[] |
getFilesWithPrefix(File dir,
String prefix)
Get a list of all files in directory that have passed prefix.
|
static org.apache.commons.io.filefilter.IOFileFilter |
getRegexFileFilter(String regex)
Get a @link java.io.FileFilter that filters files based on a regular
expression.
|
static boolean |
isReadableWithExtensionAndMagic(File f,
String uncompressedExtension,
String magic) |
static Properties |
loadProperties(File file)
Load Properties instance from a File
|
static File |
maybeRelative(File context,
String path)
Turn path into a File, relative to context (which may be ignored
if path is absolute).
|
static boolean |
moveAsideIfExists(File file) |
static org.apache.commons.lang.math.LongRange |
pagedLines(File file,
long position,
int signedDesiredLongCount,
List<String> lines) |
static org.apache.commons.lang.math.LongRange |
pagedLines(File file,
long position,
int signedDesiredLineCount,
List<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(InputStream is,
File toFile)
Read the entire stream to EOF into the passed file.
|
static void |
storeProperties(Properties p,
File file)
Store Properties instance to a File
|
static File |
tryToCanonicalize(File file) |
protected static void |
workaroundCopyFile(File src,
File dest) |
protected static LinkedList<File> pendingDeletes
public static boolean copyFile(File src, File dest) throws FileNotFoundException, IOException
src - dest - FileNotFoundExceptionIOExceptionpublic static boolean copyFile(File src, File dest, long extent) throws FileNotFoundException, IOException
src - dest - extent - Maximum number of bytes to copyFileNotFoundExceptionIOExceptionpublic static boolean copyFile(File src, File dest, long extent, boolean overwrite) throws FileNotFoundException, 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).FileNotFoundExceptionIOExceptionprotected static void workaroundCopyFile(File src, File dest) throws IOException
IOExceptionpublic static File[] getFilesWithPrefix(File dir, 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(String regex)
regex - the regular expression the files must match.public static File assertReadable(File f) throws FileNotFoundException
f - File to test.FileNotFoundException - If file does not exist or is not unreadable.public static boolean isReadableWithExtensionAndMagic(File f, String uncompressedExtension, String magic) throws IOException
f - File to test.IOException - If file not readable or other problem.public static File maybeRelative(File context, String path)
context - File context if path is relativepath - String path to make into a Filepublic static Properties loadProperties(File file) throws IOException
file - IOExceptionpublic static void storeProperties(Properties p, File file) throws IOException
p - file - destination FileIOExceptionpublic static boolean moveAsideIfExists(File file) throws IOException
IOExceptionpublic static org.apache.commons.lang.math.LongRange pagedLines(File file, long position, int signedDesiredLineCount, List<String> lines, int lineEstimate) throws 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 128IOExceptionpublic 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(File file, long position, int signedDesiredLongCount, List<String> lines) throws IOException
IOExceptionpublic static void deleteSoonerOrLater(File fileToDelete)
fileToDelete - public static long readFullyToFile(InputStream is, File toFile) throws IOException
is when done or if an exception.is - Stream to read.toFile - File to write to.IOExceptionpublic static File ensureWriteableDirectory(String dir) throws IOException
dir - Directory to test for exitence and is writeable.dir.IOException - If passed directory does not exist and is not
createable, or directory is not writeable or is not a directory.public static List<File> ensureWriteableDirectory(List<File> dirs) throws IOException
dirs - List of Files to test.dirs.IOException - If passed directory does not exist and is not
createable, or directory is not writeable or is not a directory.public static File ensureWriteableDirectory(File dir) throws IOException
dir - Directory to test for exitence and is writeable.dir.IOException - If passed directory does not exist and is not
createable, or directory is not writeable or is not a directory.public static void appendTo(File fileToAppendTo, File fileToAppendFrom) throws IOException
IOExceptionCopyright © 2015 The International Internet Preservation Consortium. All Rights Reserved.