Interface Storage
-
- All Known Implementing Classes:
CloudStorage,FileSystemStorage
public interface StorageAbstraction over any storage implementation. Paths are represented as strings because forward-slashes MUST be used as path separators. All paths into and out of implementations of this interface are required to use forward-slashes to separate path parts.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcopyDirectoryOutOf(String source, Path destination)Recursively copy the source directory from inside this storage system to an external destination.voidcopyFileInternal(String sourceFile, String destinationFile)Copy a file from inside this storage system to another destination inside it.voidcopyFileInto(Path source, String destination, String mediaType)Copy a file from outside this storage system to a destination inside.voidcreateDirectories(String path)Create the specified directory and any missing ancestors.voiddeleteDirectory(String path)Recursively delete the specified directory and all of its children.voiddeleteEmptyDirsDown(String path)Recursively delete all empty directory descendents of the specified directory.voiddeleteEmptyDirsUp(String path)Recursively delete all empty directory ancestors until the first non-empty ancestor is found.voiddeleteFile(String path)Delete the specified filevoiddeleteFiles(Collection<String> paths)Delete the specified filesbooleandirectoryIsEmpty(String directoryPath)Return true if the specified directory contains no childrenbooleanfileExists(String filePath)Indicates if the file existsOcflObjectRootDirIteratoriterateObjects()Return an iterator that iterates over every OCFL object directory in the repository.List<Listing>listDirectory(String directoryPath)Return a list of all files and directories contained in the specified directory.List<Listing>listRecursive(String directoryPath)Return a list of all leaf-node descendents of the specified directory, this includes empty leaf-node directories.voidmoveDirectoryInternal(String source, String destination)Move a directory from inside this storage system to another location inside.voidmoveDirectoryInto(Path source, String destination)Move a directory from outside this storage system to a destination inside.InputStreamread(String filePath)Streams the content of the specified fileOcflFileRetrieverreadLazy(String filePath, DigestAlgorithm algorithm, String digest)Return anOcflFileRetrieverthat can be used to read the specified file at a later time.StringreadToString(String filePath)Read the contents of the specified file to a stringvoidwrite(String filePath, byte[] content, String mediaType)Write the specified content to the specified path.
-
-
-
Method Detail
-
listDirectory
List<Listing> listDirectory(String directoryPath)
Return a list of all files and directories contained in the specified directory.- Parameters:
directoryPath- the path to the directory to list- Returns:
- list of children
- Throws:
OcflNoSuchFileException- when the directory does not exist
-
listRecursive
List<Listing> listRecursive(String directoryPath)
Return a list of all leaf-node descendents of the specified directory, this includes empty leaf-node directories. Intermediary directories are not returned.- Parameters:
directoryPath- the path to the directory to list- Returns:
- list of children
- Throws:
OcflNoSuchFileException- when the directory does not exist
-
directoryIsEmpty
boolean directoryIsEmpty(String directoryPath)
Return true if the specified directory contains no children- Parameters:
directoryPath- the path to the directory- Returns:
- true if empty
- Throws:
OcflNoSuchFileException- when the directory does not exist
-
iterateObjects
OcflObjectRootDirIterator iterateObjects()
Return an iterator that iterates over every OCFL object directory in the repository.- Returns:
- object directory iterator
-
fileExists
boolean fileExists(String filePath)
Indicates if the file exists- Parameters:
filePath- path to the file- Returns:
- true if it exists
-
read
InputStream read(String filePath)
Streams the content of the specified file- Parameters:
filePath- path to the file- Returns:
- input stream of file content
- Throws:
OcflNoSuchFileException- when the file does not exist
-
readToString
String readToString(String filePath)
Read the contents of the specified file to a string- Parameters:
filePath- path to the file- Returns:
- file contents string
- Throws:
OcflNoSuchFileException- when the file does not exist
-
readLazy
OcflFileRetriever readLazy(String filePath, DigestAlgorithm algorithm, String digest)
Return anOcflFileRetrieverthat can be used to read the specified file at a later time.- Parameters:
filePath- path to the filealgorithm- digest algorithm used to calculate the digestdigest- expected digest of the file- Returns:
- lazy file reader
-
write
void write(String filePath, byte[] content, String mediaType)
Write the specified content to the specified path. The file MUST NOT already exist.- Parameters:
filePath- path to the file to writecontent- file contentmediaType- media type of the file, may be null- Throws:
OcflFileAlreadyExistsException- when the file already exists
-
createDirectories
void createDirectories(String path)
Create the specified directory and any missing ancestors.- Parameters:
path- directory to create
-
copyDirectoryOutOf
void copyDirectoryOutOf(String source, Path destination)
Recursively copy the source directory from inside this storage system to an external destination.- Parameters:
source- internal source to copydestination- external destination- Throws:
OcflNoSuchFileException- when the source does not exist
-
copyFileInto
void copyFileInto(Path source, String destination, String mediaType)
Copy a file from outside this storage system to a destination inside. If the destination already exists, then it will be overwritten.- Parameters:
source- file to copydestination- internal destinationmediaType- media type of the file, may be null
-
copyFileInternal
void copyFileInternal(String sourceFile, String destinationFile)
Copy a file from inside this storage system to another destination inside it. If the destination already exists, then it will be overwritten.- Parameters:
sourceFile- internal file to copydestinationFile- internal destination- Throws:
OcflNoSuchFileException- when the source does not exist
-
moveDirectoryInto
void moveDirectoryInto(Path source, String destination)
Move a directory from outside this storage system to a destination inside. The destination MUST NOT already exist.- Parameters:
source- external source directorydestination- internal destination- Throws:
OcflFileAlreadyExistsException- when the destination already exists
-
moveDirectoryInternal
void moveDirectoryInternal(String source, String destination)
Move a directory from inside this storage system to another location inside. The destination MUST NOT already exist.- Parameters:
source- internal source directorydestination- internal destination- Throws:
OcflFileAlreadyExistsException- when the destination already existsOcflNoSuchFileException- when the source does not exist
-
deleteDirectory
void deleteDirectory(String path)
Recursively delete the specified directory and all of its children.- Parameters:
path- path to delete
-
deleteFile
void deleteFile(String path)
Delete the specified file- Parameters:
path- file to delete
-
deleteFiles
void deleteFiles(Collection<String> paths)
Delete the specified files- Parameters:
paths- files to delete
-
deleteEmptyDirsDown
void deleteEmptyDirsDown(String path)
Recursively delete all empty directory descendents of the specified directory. The starting path is eligible for deletion.- Parameters:
path- starting path
-
deleteEmptyDirsUp
void deleteEmptyDirsUp(String path)
Recursively delete all empty directory ancestors until the first non-empty ancestor is found. The starting path is eligible for deletion.- Parameters:
path- starting path
-
-