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 Details

    • listDirectory

      List<Item> listDirectory(String directoryPath) throws IOException
      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 layers
      NotDirectoryException - if the path exists, but is not a directory
      IOException
    • listRecursive

      List<Item> listRecursive(String directoryPath) throws IOException
      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 layers
      NotDirectoryException - if the path exists, but is not a directory
      IOException
    • existsPathLike

      boolean existsPathLike(String path)
      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

      InputStream readFile(String path) throws IOException
      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

      void writeFile(String path, InputStream content) throws IOException
      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 root
      content - the content to write
      Throws:
      IOException
    • moveDirectoryInto

      void moveDirectoryInto(Path source, String destination) throws IOException
      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 move
      destination - 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 exist
      IOException
    • moveDirectoryInternal

      void moveDirectoryInternal(String source, String destination) throws IOException
      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 root
      destination - 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 exist
      IllegalStateException - if the implementation has persisted the source directory, or part of it in a way that does not allow it to be moved
      IOException
    • deleteDirectory

      void deleteDirectory(String path) throws IOException
      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 directory
      IllegalStateException - if the implementation has persisted the directory, or part of it in a way that does not allow it to be deleted
      IOException
    • deleteFiles

      void deleteFiles(List<String> paths) throws IOException
      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 directory
      IOException
    • createDirectory

      void createDirectory(String path) throws IOException
      Throws:
      IOException
    • copyDirectoryOutOf

      void copyDirectoryOutOf(String source, Path destination) throws IOException
      Throws:
      IOException