public class FileUtils extends Object
| Modifier and Type | Class and Description | 
|---|---|
static class  | 
FileUtils.FileCopyResult
Keeps results of a file copy, including children and total size of the resultant files. 
 | 
static interface  | 
FileUtils.OutputStreamConsumer  | 
| Modifier and Type | Field and Description | 
|---|---|
static com.google.common.base.Predicate<Throwable> | 
IS_EXCEPTION
Useful for retry functionality that doesn't want to stop Throwables, but does want to retry on Exceptions 
 | 
| Constructor and Description | 
|---|
FileUtils()  | 
| Modifier and Type | Method and Description | 
|---|---|
static MappedByteBufferHandler | 
map(File file)
Fully maps a file read-only in to memory as per
  
FileChannel.map(FileChannel.MapMode, long, long). | 
static FileUtils.FileCopyResult | 
retryCopy(com.google.common.io.ByteSource byteSource,
         File outFile,
         com.google.common.base.Predicate<Throwable> shouldRetry,
         int maxAttempts)
Copy input byte source to outFile. 
 | 
static void | 
writeAtomically(File file,
               FileUtils.OutputStreamConsumer f)
Write to a file atomically, by first writing to a temporary file in the same directory and then moving it to
 the target location. 
 | 
public static final com.google.common.base.Predicate<Throwable> IS_EXCEPTION
public static FileUtils.FileCopyResult retryCopy(com.google.common.io.ByteSource byteSource, File outFile, com.google.common.base.Predicate<Throwable> shouldRetry, int maxAttempts)
byteSource - Supplier for an input stream that is to be copied. The resulting stream is closed each iterationoutFile - Where the file should be written to.shouldRetry - Predicate indicating if an error is recoverable and should be retried.maxAttempts - The maximum number of assumed recoverable attempts to try before completely failing.RuntimeException - wrapping the inner exception on failure.public static MappedByteBufferHandler map(File file) throws IOException
FileChannel.map(FileChannel.MapMode, long, long).
 Files are mapped from offset 0 to its length.
This only works for files <= Integer.MAX_VALUE bytes.
 
Similar to Files.map(File), but returns MappedByteBufferHandler, that makes it easier to unmap
 the buffer within try-with-resources pattern:
 
 try (MappedByteBufferHandler fileMappingHandler = FileUtils.map(file)) {
   ByteBuffer fileMapping = fileMappingHandler.get();
   // use mapped buffer
 }file - the file to mapMappedByteBufferHandler, wrapping a read-only buffer reflecting fileFileNotFoundException - if the file does not existIOException - if an I/O error occursFileChannel.map(FileChannel.MapMode, long, long)public static void writeAtomically(File file, FileUtils.OutputStreamConsumer f) throws IOException
IOExceptionCopyright © 2011–2018. All rights reserved.