Interface Storage

  • All Known Implementing Classes:
    CloudStorage, FileSystemStorage

    public interface Storage
    Abstraction 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 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 an OcflFileRetriever that can be used to read the specified file at a later time.
        Parameters:
        filePath - path to the file
        algorithm - digest algorithm used to calculate the digest
        digest - 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 write
        content - file content
        mediaType - 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 copy
        destination - 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 copy
        destination - internal destination
        mediaType - 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 copy
        destinationFile - 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 directory
        destination - 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 directory
        destination - internal destination
        Throws:
        OcflFileAlreadyExistsException - when the destination already exists
        OcflNoSuchFileException - 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