public final class InMemoryFileSystem extends java.lang.Object implements FileSystem, org.junit.rules.TestRule
| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<java.io.File,okio.Buffer> |
files |
private java.util.Map<okio.Sink,java.io.File> |
openSinks |
private java.util.Map<okio.Source,java.io.File> |
openSources |
SYSTEM| Constructor and Description |
|---|
InMemoryFileSystem() |
| Modifier and Type | Method and Description |
|---|---|
okio.Sink |
appendingSink(java.io.File file)
Writes to
file, appending if data is already present. |
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
void |
delete(java.io.File file)
Deletes
file if it exists. |
void |
deleteContents(java.io.File directory)
Recursively delete the contents of
directory. |
void |
ensureResourcesClosed() |
boolean |
exists(java.io.File file)
Returns true if
file exists on the file system. |
void |
rename(java.io.File from,
java.io.File to)
Renames
from to to. |
okio.Sink |
sink(java.io.File file)
Writes to
file, discarding any data already present. |
private okio.Sink |
sink(java.io.File file,
boolean appending) |
long |
size(java.io.File file)
Returns the number of bytes stored in
file, or 0 if it does not exist. |
okio.Source |
source(java.io.File file)
Reads from
file. |
private final java.util.Map<java.io.File,okio.Buffer> files
private final java.util.Map<okio.Source,java.io.File> openSources
private final java.util.Map<okio.Sink,java.io.File> openSinks
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description)
apply in interface org.junit.rules.TestRulepublic void ensureResourcesClosed()
public okio.Source source(java.io.File file)
throws java.io.FileNotFoundException
FileSystemfile.source in interface FileSystemjava.io.FileNotFoundExceptionpublic okio.Sink sink(java.io.File file)
throws java.io.FileNotFoundException
FileSystemfile, discarding any data already present. Creates parent directories if
necessary.sink in interface FileSystemjava.io.FileNotFoundExceptionpublic okio.Sink appendingSink(java.io.File file)
throws java.io.FileNotFoundException
FileSystemfile, appending if data is already present. Creates parent directories if
necessary.appendingSink in interface FileSystemjava.io.FileNotFoundExceptionprivate okio.Sink sink(java.io.File file,
boolean appending)
public void delete(java.io.File file)
throws java.io.IOException
FileSystemfile if it exists. Throws if the file exists and cannot be deleted.delete in interface FileSystemjava.io.IOExceptionpublic boolean exists(java.io.File file)
FileSystemfile exists on the file system.exists in interface FileSystempublic long size(java.io.File file)
FileSystemfile, or 0 if it does not exist.size in interface FileSystempublic void rename(java.io.File from,
java.io.File to)
throws java.io.IOException
FileSystemfrom to to. Throws if the file cannot be renamed.rename in interface FileSystemjava.io.IOExceptionpublic void deleteContents(java.io.File directory)
throws java.io.IOException
FileSystemdirectory. Throws an IOException if any file could
not be deleted, or if dir is not a readable directory.deleteContents in interface FileSystemjava.io.IOException