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.TestRule
public void ensureResourcesClosed()
public okio.Source source(java.io.File file) throws java.io.FileNotFoundException
FileSystem
file
.source
in interface FileSystem
java.io.FileNotFoundException
public okio.Sink sink(java.io.File file) throws java.io.FileNotFoundException
FileSystem
file
, discarding any data already present. Creates parent directories if
necessary.sink
in interface FileSystem
java.io.FileNotFoundException
public okio.Sink appendingSink(java.io.File file) throws java.io.FileNotFoundException
FileSystem
file
, appending if data is already present. Creates parent directories if
necessary.appendingSink
in interface FileSystem
java.io.FileNotFoundException
private okio.Sink sink(java.io.File file, boolean appending)
public void delete(java.io.File file) throws java.io.IOException
FileSystem
file
if it exists. Throws if the file exists and cannot be deleted.delete
in interface FileSystem
java.io.IOException
public boolean exists(java.io.File file)
FileSystem
file
exists on the file system.exists
in interface FileSystem
public long size(java.io.File file)
FileSystem
file
, or 0 if it does not exist.size
in interface FileSystem
public void rename(java.io.File from, java.io.File to) throws java.io.IOException
FileSystem
from
to to
. Throws if the file cannot be renamed.rename
in interface FileSystem
java.io.IOException
public void deleteContents(java.io.File directory) throws java.io.IOException
FileSystem
directory
. Throws an IOException if any file could
not be deleted, or if dir
is not a readable directory.deleteContents
in interface FileSystem
java.io.IOException