public class MockFileOp extends FileSystemFileOp
FileOpImpl that wraps some common File
operations on files and folders.
This version does not perform any file operation. Instead it records a textual representation of all the file operations performed.
To avoid cross-platform path issues (e.g. Windows path), the methods here should
always use rooted (aka absolute) unix-looking paths, e.g. "/dir1/dir2/file3".
When processing File, you can convert them using getAgnosticAbsPath(File).
mIsWindowsEMPTY_FILE_ARRAY| Constructor and Description |
|---|
MockFileOp() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
canWrite(java.io.File file)
Invokes
File.canWrite() on the given file. |
void |
deleteOnExit(java.io.File file) |
java.io.File |
ensureRealFile(java.io.File in)
If
in is an in-memory file, write it out as a proper file and return it. |
java.lang.String |
getAgnosticAbsPath(java.io.File file) |
java.lang.String |
getAgnosticAbsPath(java.lang.String path) |
byte[] |
getContent(java.io.File file) |
java.lang.String[] |
getExistingFiles()
Returns the list of paths added using
recordExistingFile(String)
and eventually updated by FileSystemFileOp.delete(File) operations. |
java.lang.String[] |
getExistingFolders()
Returns the list of folder paths added using
recordExistingFolder(String)
and eventually updated FileSystemFileOp.delete(File) or FileSystemFileOp.mkdirs(File) operations. |
java.nio.file.FileSystem |
getFileSystem()
Gets the
FileSystem this is based on. |
boolean |
hasRecordedExistingFolder(java.io.File folder)
Returns true if a folder with the given path has been recorded.
|
void |
recordExistingFile(java.io.File file)
Records a new absolute file path.
|
void |
recordExistingFile(java.lang.String absFilePath)
Records a new absolute file path.
|
void |
recordExistingFile(java.lang.String absFilePath,
byte[] inputStream)
Records a new absolute file path and its input stream content.
|
void |
recordExistingFile(java.lang.String absFilePath,
long lastModified,
byte[] inputStream)
Records a new absolute file path and its input stream content.
|
void |
recordExistingFile(java.lang.String absFilePath,
long lastModified,
java.lang.String content)
Records a new absolute file path and its input stream content.
|
void |
recordExistingFile(java.lang.String absFilePath,
java.lang.String content)
Records a new absolute file path and its input stream content.
|
void |
recordExistingFolder(java.io.File folder)
Records a new absolute folder path.
|
void |
recordExistingFolder(java.lang.String absFolderPath)
Records a new absolute folder path.
|
void |
reset()
Resets the internal state, as if the object had been newly created.
|
void |
setIsWindows(boolean isWindows) |
java.nio.file.Path |
toPath(java.io.File file)
Convert the given
File into a Path, using some means appropriate to this
FileOp. |
canExecute, copyFile, createNewFile, delete, deleteFileOrFolder, exists, isDirectory, isFile, isSameFile, isWindows, lastModified, length, list, listFiles, listFiles, mkdirs, newFileInputStream, newFileOutputStream, newFileOutputStream, renameTo, setExecutablePermission, setLastModified, setReadOnly, toStringpublic java.nio.file.FileSystem getFileSystem()
FileSystemFileOpFileSystem this is based on.getFileSystem in class FileSystemFileOppublic void reset()
public void deleteOnExit(java.io.File file)
File.deleteOnExit()public void setIsWindows(boolean isWindows)
public boolean canWrite(@NonNull
java.io.File file)
FileOpFile.canWrite() on the given file.canWrite in interface FileOpcanWrite in class FileSystemFileOp@NonNull
public java.lang.String getAgnosticAbsPath(@NonNull
java.io.File file)
@NonNull
public java.lang.String getAgnosticAbsPath(@NonNull
java.lang.String path)
public void recordExistingFile(@NonNull
java.io.File file)
public void recordExistingFile(@NonNull
java.lang.String absFilePath)
The syntax should always look "unix-like", e.g. "/dir/file".
On Windows that means you'll want to use getAgnosticAbsPath(File).
absFilePath - A unix-like file path, e.g. "/dir/file"public void recordExistingFile(@NonNull
java.lang.String absFilePath,
@Nullable
byte[] inputStream)
The syntax should always look "unix-like", e.g. "/dir/file".
On Windows that means you'll want to use getAgnosticAbsPath(File).
absFilePath - A unix-like file path, e.g. "/dir/file"inputStream - A non-null byte array of content to return
via FileSystemFileOp.newFileInputStream(File).public void recordExistingFile(@NonNull
java.lang.String absFilePath,
@NonNull
java.lang.String content)
The syntax should always look "unix-like", e.g. "/dir/file".
On Windows that means you'll want to use getAgnosticAbsPath(File).
absFilePath - A unix-like file path, e.g. "/dir/file"content - A non-null UTF-8 content string to return
via FileSystemFileOp.newFileInputStream(File).public void recordExistingFile(@NonNull
java.lang.String absFilePath,
long lastModified,
@Nullable
byte[] inputStream)
The syntax should always look "unix-like", e.g. "/dir/file".
On Windows that means you'll want to use getAgnosticAbsPath(File).
absFilePath - A unix-like file path, e.g. "/dir/file"inputStream - A non-null byte array of content to return
via FileSystemFileOp.newFileInputStream(File).public void recordExistingFile(@NonNull
java.lang.String absFilePath,
long lastModified,
@NonNull
java.lang.String content)
The syntax should always look "unix-like", e.g. "/dir/file".
On Windows that means you'll want to use getAgnosticAbsPath(File).
absFilePath - A unix-like file path, e.g. "/dir/file"content - A non-null UTF-8 content string to return
via FileSystemFileOp.newFileInputStream(File).public void recordExistingFolder(java.io.File folder)
public void recordExistingFolder(java.lang.String absFolderPath)
The syntax should always look "unix-like", e.g. "/dir/file".
On Windows that means you'll want to use getAgnosticAbsPath(File).
absFolderPath - A unix-like folder path, e.g. "/dir/file"public boolean hasRecordedExistingFolder(java.io.File folder)
@NonNull public java.lang.String[] getExistingFiles()
recordExistingFile(String)
and eventually updated by FileSystemFileOp.delete(File) operations.
The returned list is sorted by alphabetic absolute path string.
@NonNull public java.lang.String[] getExistingFolders()
recordExistingFolder(String)
and eventually updated FileSystemFileOp.delete(File) or FileSystemFileOp.mkdirs(File) operations.
The returned list is sorted by alphabetic absolute path string.
public java.io.File ensureRealFile(@NonNull
java.io.File in)
throws java.io.IOException
FileOpin is an in-memory file, write it out as a proper file and return it.
Otherwise just return in.java.io.IOExceptionpublic byte[] getContent(java.io.File file)
@NonNull
public java.nio.file.Path toPath(@NonNull
java.io.File file)
FileOpFile into a Path, using some means appropriate to this
FileOp.toPath in interface FileOptoPath in class FileSystemFileOp