Package nl.knaw.dans.layerstore
Interface ItemStore
- All Known Implementing Classes:
LayeredItemStore
public interface ItemStore
An ItemStore stores "items", which are files and directories. The name "item" was chosen to avoid name clashes with the java.io.File class. This library implements a layered way of storing items, but other implementations are conceivable. The main reason for defining this interface in more general terms is to hide the details of the underlying storage mechanism from the client code.
An ItemStore has a storage root, which is implementation dependent.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
copyDirectoryOutOf
(String source, Path destination) void
createDirectory
(String path) void
deleteDirectory
(String path) Deletes the directory at the given path, including all its contents.void
deleteFiles
(List<String> paths) Deletes the files at the given paths.boolean
existsPathLike
(String path) Returns whether a path with the given pattern exists in the store.listDirectory
(String directoryPath) Returns the items in the given directory, taking into account the complete stack of layers.listRecursive
(String directoryPath) Returns the files and directories in the given directory and its subdirectories.void
moveDirectoryInternal
(String source, String destination) Moves the directory inside the store to the given destination.void
moveDirectoryInto
(Path source, String destination) Moves the directory outside the store into the given destination.Opens an input stream to the file at the given path.void
writeFile
(String path, InputStream content) Writes the given content to the file at the given path.
-
Method Details
-
listDirectory
Returns the items in the given directory, taking into account the complete stack of layers.- Parameters:
directoryPath
- the directory path relative to the storage root- Returns:
- the items in the directory
- Throws:
NoSuchFileException
- if the directory does not exist in any of the layersNotDirectoryException
- if the path exists, but is not a directoryIOException
-
listRecursive
Returns the files and directories in the given directory and its subdirectories.- Parameters:
directoryPath
- the directory path relative to the storage root- Returns:
- the items in the directory and its subdirectories
- Throws:
NoSuchFileException
- if the directory does not exist in any of the layersNotDirectoryException
- if the path exists, but is not a directoryIOException
-
existsPathLike
Returns whether a path with the given pattern exists in the store.- Parameters:
path
- a path, which may contain the SQL wildcard character '%'- Returns:
- true if a path exists that matches the pattern, false otherwise
-
readFile
Opens an input stream to the file at the given path.- Parameters:
path
- the path of the file relative to the storage root- Returns:
- an input stream to the file
- Throws:
IOException
- if the file could not be opened
-
writeFile
Writes the given content to the file at the given path. If the file does not exist yet, it is created.- Parameters:
path
- the path of the file relative to the storage rootcontent
- the content to write- Throws:
IOException
-
moveDirectoryInto
Moves the directory outside the store into the given destination. The parent of the destination must exist, but the destination itself must not exist yet.- Parameters:
source
- the path of the directory to movedestination
- the path of the destination directory relative to the storage root- Throws:
IllegalArgumentException
- if the source does not exist or is not a directory, or if the destination already exists, or its parent does not existIOException
-
moveDirectoryInternal
Moves the directory inside the store to the given destination. The destination must not exist yet, but its parent must exist.- Parameters:
source
- the path of the directory to move relative to the storage rootdestination
- the path of the destination directory relative to the storage root- Throws:
IllegalArgumentException
- if the source does not exist or is not a directory, or if the destination already exists, or its parent does not existIllegalStateException
- if the implementation has persisted the source directory, or part of it in a way that does not allow it to be movedIOException
-
deleteDirectory
Deletes the directory at the given path, including all its contents.- Parameters:
path
- the path of the directory relative to the storage root- Throws:
IllegalArgumentException
- if the path does not exist or is not a directoryIllegalStateException
- if the implementation has persisted the directory, or part of it in a way that does not allow it to be deletedIOException
-
deleteFiles
Deletes the files at the given paths.- Parameters:
paths
- the paths of the files relative to the storage root- Throws:
IllegalArgumentException
- if any of the paths does not exist or is a directoryIOException
-
createDirectory
- Throws:
IOException
-
copyDirectoryOutOf
- Throws:
IOException
-