Package com.squareup.okhttp.internal.io
Interface FileSystem
-
public interface FileSystemAccess to read and write files on a hierarchical data store. Most callers should use theSYSTEMimplementation, which uses the host machine's local file system. Alternate implementations may be used to inject faults (for testing) or to transform stored data (to add encryption, for example).All operations on a file system are racy. For example, guarding a call to
source(java.io.File)withexists(java.io.File)does not guarantee thatFileNotFoundExceptionwill not be thrown. The file may be moved between the two calls!This interface is less ambitious than
FileSystemintroduced in Java 7. It lacks important features like file watching, metadata, permissions, and disk space information. In exchange for these limitations, this interface is easier to implement and works on all versions of Java and Android.
-
-
Field Summary
Fields Modifier and Type Field Description static FileSystemSYSTEMThe host machine's local file system.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description SinkappendingSink(File file)Writes tofile, appending if data is already present.voiddelete(File file)Deletesfileif it exists.voiddeleteContents(File directory)Recursively delete the contents ofdirectory.booleanexists(File file)Returns true iffileexists on the file system.voidrename(File from, File to)Renamesfromtoto.Sinksink(File file)Writes tofile, discarding any data already present.longsize(File file)Returns the number of bytes stored infile, or 0 if it does not exist.Sourcesource(File file)Reads fromfile.
-
-
-
Field Detail
-
SYSTEM
static final FileSystem SYSTEM
The host machine's local file system.
-
-
Method Detail
-
source
Source source(File file) throws FileNotFoundException
Reads fromfile.- Throws:
FileNotFoundException
-
sink
Sink sink(File file) throws FileNotFoundException
Writes tofile, discarding any data already present. Creates parent directories if necessary.- Throws:
FileNotFoundException
-
appendingSink
Sink appendingSink(File file) throws FileNotFoundException
Writes tofile, appending if data is already present. Creates parent directories if necessary.- Throws:
FileNotFoundException
-
delete
void delete(File file) throws IOException
Deletesfileif it exists. Throws if the file exists and cannot be deleted.- Throws:
IOException
-
exists
boolean exists(File file) throws IOException
Returns true iffileexists on the file system.- Throws:
IOException
-
size
long size(File file)
Returns the number of bytes stored infile, or 0 if it does not exist.
-
rename
void rename(File from, File to) throws IOException
Renamesfromtoto. Throws if the file cannot be renamed.- Throws:
IOException
-
deleteContents
void deleteContents(File directory) throws IOException
Recursively delete the contents ofdirectory. Throws an IOException if any file could not be deleted, or ifdiris not a readable directory.- Throws:
IOException
-
-