public abstract class AbstractFakeFileSystem extends Object implements FileSystem
If the createParentDirectoriesAutomatically
property is set to true
,
then creating a directory or file will automatically create any parent directories (recursively)
that do not already exist. If false
, then creating a directory or file throws an
exception if its parent directory does not exist. This value defaults to true
.
The directoryListingFormatter
property holds an instance of DirectoryListingFormatter
,
used by the formatDirectoryListing
method to format directory listings in a
filesystem-specific manner. This property must be initialized by concrete subclasses.
Constructor and Description |
---|
AbstractFakeFileSystem() |
Modifier and Type | Method and Description |
---|---|
void |
add(FileSystemEntry entry)
Add the specified file system entry (file or directory) to this file system
|
protected void |
checkForInvalidFilename(String path)
Throw an InvalidFilenameException if the specified path is not valid.
|
protected String |
componentsToPath(List components)
Build a path from the specified list of path components
|
boolean |
delete(String path)
Delete the file or directory specified by the path.
|
boolean |
exists(String path)
Return true if there exists a file or directory at the specified path
|
String |
formatDirectoryListing(FileSystemEntry fileSystemEntry)
Return the formatted directory listing entry for the file represented by the specified FileSystemEntry
|
DirectoryListingFormatter |
getDirectoryListingFormatter() |
FileSystemEntry |
getEntry(String path)
Returns the FileSystemEntry object representing the file system entry at the specified path, or null
if the path does not specify an existing file or directory within this file system.
|
protected String |
getFileSystemEntryKey(String path)
Return the normalized and unique key used to access the file system entry
|
String |
getName(String path)
Returns the name of the file or directory denoted by this abstract
pathname.
|
String |
getParent(String path)
Return the parent path of the specified path.
|
protected FileSystemEntry |
getRequiredEntry(String path)
Return the FileSystemEntry for the specified path.
|
protected String |
getSeparator() |
protected abstract char |
getSeparatorChar() |
boolean |
isAbsolute(String path)
Return true if the specified path designates an absolute file path.
|
boolean |
isCreateParentDirectoriesAutomatically() |
boolean |
isDirectory(String path)
Return true if the specified path designates an existing directory, false otherwise
|
boolean |
isFile(String path)
Return true if the specified path designates an existing file, false otherwise
|
protected abstract boolean |
isRoot(String pathComponent) |
protected abstract boolean |
isSeparator(char c)
Return true if the specified char is a separator character for this filesystem
|
protected abstract boolean |
isValidName(String path) |
List |
listFiles(String path)
Return the List of FileSystemEntry objects for the files in the specified directory or group of
files.
|
List |
listNames(String path)
Return the List of filenames in the specified directory path or file path.
|
protected String |
normalize(String path)
Return the standard, normalized form of the path.
|
protected List |
normalizedComponents(String path)
Return the components of the specified path as a List.
|
String |
path(String path1,
String path2)
Build a path from the two path components.
|
void |
rename(String fromPath,
String toPath)
Rename the file or directory.
|
protected void |
renamePath(FileSystemEntry entry,
String toPath)
Rename the file system entry to the specified path name
|
void |
setCreateParentDirectoriesAutomatically(boolean createParentDirectoriesAutomatically) |
void |
setDirectoryListingFormatter(DirectoryListingFormatter directoryListingFormatter) |
void |
setEntries(List entriesToAdd)
Add each of the entries in the specified List to this filesystem.
|
String |
toString() |
public boolean isCreateParentDirectoriesAutomatically()
public void setCreateParentDirectoriesAutomatically(boolean createParentDirectoriesAutomatically)
public DirectoryListingFormatter getDirectoryListingFormatter()
public void setDirectoryListingFormatter(DirectoryListingFormatter directoryListingFormatter)
public void setEntries(List entriesToAdd)
entriesToAdd
- - the List of FileSystemEntry entries to addpublic void add(FileSystemEntry entry)
add
in interface FileSystem
entry
- - the FileSystemEntry to addpublic boolean delete(String path)
delete
in interface FileSystem
path
- - the path of the file or directory to deleteAssertFailedException
- - if path is nullFileSystem.delete(java.lang.String)
public boolean exists(String path)
exists
in interface FileSystem
path
- - the pathAssertionError
- - if path is nullFileSystem.exists(java.lang.String)
public boolean isDirectory(String path)
isDirectory
in interface FileSystem
path
- - the pathAssertionError
- - if path is nullFileSystem.isDirectory(java.lang.String)
public boolean isFile(String path)
isFile
in interface FileSystem
path
- - the pathAssertionError
- - if path is nullFileSystem.isFile(java.lang.String)
public List listFiles(String path)
listFiles
in interface FileSystem
path
- - the path specifying a directory or group of files; may contain wildcards (? or *)FileSystem.listFiles(java.lang.String)
public List listNames(String path)
listNames
in interface FileSystem
path
- - the path specifying a directory or group of files; may contain wildcards (? or *)AssertionError
- - if path is nullFileSystem.listNames(java.lang.String)
public void rename(String fromPath, String toPath)
rename
in interface FileSystem
fromPath
- - the source (old) path + filenametoPath
- - the target (new) path + filenameAssertionError
- - if fromPath or toPath is nullFileSystemException
- - if the rename fails.public String toString()
toString
in class Object
Object.toString()
public String formatDirectoryListing(FileSystemEntry fileSystemEntry)
formatDirectoryListing
in interface FileSystem
fileSystemEntry
- - the FileSystemEntry representing the file or directory entry to be formattedpublic String path(String path1, String path2)
path
in interface FileSystem
path1
- - the first path component may be null or emptypath2
- - the second path component may be null or emptypublic String getParent(String path)
path
specifies a filename,
then this method returns the path of the directory containing that file. If path
specifies a directory, the this method returns its parent directory. If path
is
empty or does not have a parent component, then return an empty string.
All path separators in the returned path are converted to the system-dependent separator character.
getParent
in interface FileSystem
path
- - the pathpath
has no parentAssertionError
- - if path is nullpublic String getName(String path)
path
- - the pathpublic FileSystemEntry getEntry(String path)
getEntry
in interface FileSystem
path
- - the path of the file or directory within this file systemFileSystem.getEntry(String)
protected abstract boolean isValidName(String path)
path
- - the pathprotected abstract char getSeparatorChar()
protected abstract boolean isRoot(String pathComponent)
pathComponent
- - the component (piece) of the path to checkprotected abstract boolean isSeparator(char c)
c
- - the character to testprotected String getSeparator()
protected String getFileSystemEntryKey(String path)
path
- - the pathprotected String normalize(String path)
path
- - the pathAssertionError
- - if path is nullprotected void checkForInvalidFilename(String path)
path
- - the pathprotected void renamePath(FileSystemEntry entry, String toPath)
entry
- - the file system entrytoPath
- - the TO path (normalized)protected FileSystemEntry getRequiredEntry(String path)
path
- - the pathFileSystemException
- - if the specified path does not existprotected List normalizedComponents(String path)
path
- - the pathprotected String componentsToPath(List components)
components
- - the list of path componentspublic boolean isAbsolute(String path)
isAbsolute
in interface FileSystem
path
- - the pathAssertionError
- - if path is nullCopyright © 2016. All rights reserved.