Class LayeredItemStore

java.lang.Object
nl.knaw.dans.layerstore.LayeredItemStore
All Implemented Interfaces:
ItemStore

public class LayeredItemStore extends Object implements ItemStore
An implementation of FileStore that stores files and directories as a stack of layers. A layer can be staged or archived. Staged layers can be modified, archived layers are read-only. To transform the layered file store into a regular file system directory, each layer must be unarchived (if it was archived) to a staging directory and the staging directories must be copied into a single directory, starting with the oldest layer and ending with the newest layer. Files in newer layers overwrite files in older layers.

The LayeredFileStore is backed by a LayerDatabase to support storage of layers in a way that may not be fast enough for direct access, for example on tape. See the LayerDatabase interface for more information.

See Also:
  • Constructor Details

  • Method Details

    • listDirectory

      public List<Item> listDirectory(String directoryPath) throws IOException
      Description copied from interface: ItemStore
      Returns the items in the given directory, taking into account the complete stack of layers.
      Specified by:
      listDirectory in interface ItemStore
      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 layers
      NotDirectoryException - if the path exists, but is not a directory
      IOException
    • listRecursive

      public List<Item> listRecursive(String directoryPath) throws IOException
      Description copied from interface: ItemStore
      Returns the files and directories in the given directory and its subdirectories.
      Specified by:
      listRecursive in interface ItemStore
      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 layers
      NotDirectoryException - if the path exists, but is not a directory
      IOException
    • existsPathLike

      public boolean existsPathLike(String path)
      Description copied from interface: ItemStore
      Returns whether a path with the given pattern exists in the store.
      Specified by:
      existsPathLike in interface ItemStore
      Parameters:
      path - a path, which may contain the SQL wildcard character '%'
      Returns:
      true if a path exists that matches the pattern, false otherwise
    • readFile

      public InputStream readFile(String path) throws IOException
      Description copied from interface: ItemStore
      Opens an input stream to the file at the given path.
      Specified by:
      readFile in interface ItemStore
      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

      public void writeFile(String path, InputStream content) throws IOException
      Description copied from interface: ItemStore
      Writes the given content to the file at the given path. If the file does not exist yet, it is created.
      Specified by:
      writeFile in interface ItemStore
      Parameters:
      path - the path of the file relative to the storage root
      content - the content to write
      Throws:
      IOException
    • moveDirectoryInto

      public void moveDirectoryInto(Path source, String destination) throws IOException
      Description copied from interface: ItemStore
      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.
      Specified by:
      moveDirectoryInto in interface ItemStore
      Parameters:
      source - the path of the directory to move
      destination - the path of the destination directory relative to the storage root
      Throws:
      IOException
    • moveDirectoryInternal

      public void moveDirectoryInternal(String source, String destination) throws IOException
      Description copied from interface: ItemStore
      Moves the directory inside the store to the given destination. The destination must not exist yet, but its parent must exist.
      Specified by:
      moveDirectoryInternal in interface ItemStore
      Parameters:
      source - the path of the directory to move relative to the storage root
      destination - the path of the destination directory relative to the storage root
      Throws:
      IOException
    • deleteDirectory

      public void deleteDirectory(String path) throws IOException
      Description copied from interface: ItemStore
      Deletes the directory at the given path, including all its contents.
      Specified by:
      deleteDirectory in interface ItemStore
      Parameters:
      path - the path of the directory relative to the storage root
      Throws:
      IOException
    • deleteFiles

      public void deleteFiles(List<String> paths) throws IOException
      Description copied from interface: ItemStore
      Deletes the files at the given paths.
      Specified by:
      deleteFiles in interface ItemStore
      Parameters:
      paths - the paths of the files relative to the storage root
      Throws:
      IOException
    • createDirectory

      public void createDirectory(String path) throws IOException
      Specified by:
      createDirectory in interface ItemStore
      Throws:
      IOException
    • copyDirectoryOutOf

      public void copyDirectoryOutOf(String source, Path destination) throws IOException
      Specified by:
      copyDirectoryOutOf in interface ItemStore
      Throws:
      IOException