Class CloudStorage

  • All Implemented Interfaces:
    Storage

    public class CloudStorage
    extends Object
    implements Storage
    Storage abstraction over cloud storage providers.
    • Constructor Detail

      • CloudStorage

        public CloudStorage​(CloudClient client)
    • Method Detail

      • listDirectory

        public List<Listing> listDirectory​(String directoryPath)
        Return a list of all files and directories contained in the specified directory.
        Specified by:
        listDirectory in interface Storage
        Parameters:
        directoryPath - the path to the directory to list
        Returns:
        list of children
      • listRecursive

        public 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.
        Specified by:
        listRecursive in interface Storage
        Parameters:
        directoryPath - the path to the directory to list
        Returns:
        list of children
      • directoryIsEmpty

        public boolean directoryIsEmpty​(String directoryPath)
        Return true if the specified directory contains no children
        Specified by:
        directoryIsEmpty in interface Storage
        Parameters:
        directoryPath - the path to the directory
        Returns:
        true if empty
      • iterateObjects

        public OcflObjectRootDirIterator iterateObjects()
        Return an iterator that iterates over every OCFL object directory in the repository.
        Specified by:
        iterateObjects in interface Storage
        Returns:
        object directory iterator
      • fileExists

        public boolean fileExists​(String filePath)
        Indicates if the file exists
        Specified by:
        fileExists in interface Storage
        Parameters:
        filePath - path to the file
        Returns:
        true if it exists
      • read

        public InputStream read​(String filePath)
        Streams the content of the specified file
        Specified by:
        read in interface Storage
        Parameters:
        filePath - path to the file
        Returns:
        input stream of file content
      • readToString

        public String readToString​(String filePath)
        Read the contents of the specified file to a string
        Specified by:
        readToString in interface Storage
        Parameters:
        filePath - path to the file
        Returns:
        file contents string
      • readLazy

        public OcflFileRetriever readLazy​(String filePath,
                                          DigestAlgorithm algorithm,
                                          String digest)
        Return an OcflFileRetriever that can be used to read the specified file at a later time.
        Specified by:
        readLazy in interface Storage
        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

        public void write​(String filePath,
                          byte[] content,
                          String mediaType)
        Write the specified content to the specified path. The file MUST NOT already exist.
        Specified by:
        write in interface Storage
        Parameters:
        filePath - path to the file to write
        content - file content
        mediaType - media type of the file, may be null
      • createDirectories

        public void createDirectories​(String path)
        Create the specified directory and any missing ancestors.
        Specified by:
        createDirectories in interface Storage
        Parameters:
        path - directory to create
      • copyDirectoryOutOf

        public void copyDirectoryOutOf​(String source,
                                       Path outputPath)
        Recursively copy the source directory from inside this storage system to an external destination.
        Specified by:
        copyDirectoryOutOf in interface Storage
        Parameters:
        source - internal source to copy
        outputPath - external destination
      • copyFileInto

        public 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.
        Specified by:
        copyFileInto in interface Storage
        Parameters:
        source - file to copy
        destination - internal destination
        mediaType - media type of the file, may be null
      • copyFileInternal

        public 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.
        Specified by:
        copyFileInternal in interface Storage
        Parameters:
        sourceFile - internal file to copy
        destinationFile - internal destination
      • moveDirectoryInto

        public void moveDirectoryInto​(Path source,
                                      String destination)
        Move a directory from outside this storage system to a destination inside. The destination MUST NOT already exist.
        Specified by:
        moveDirectoryInto in interface Storage
        Parameters:
        source - external source directory
        destination - internal destination
      • moveDirectoryInternal

        public void moveDirectoryInternal​(String source,
                                          String destination)
        Move a directory from inside this storage system to another location inside. The destination MUST NOT already exist.
        Specified by:
        moveDirectoryInternal in interface Storage
        Parameters:
        source - internal source directory
        destination - internal destination
      • deleteDirectory

        public void deleteDirectory​(String path)
        Recursively delete the specified directory and all of its children.
        Specified by:
        deleteDirectory in interface Storage
        Parameters:
        path - path to delete
      • deleteFile

        public void deleteFile​(String path)
        Delete the specified file
        Specified by:
        deleteFile in interface Storage
        Parameters:
        path - file to delete
      • deleteFiles

        public void deleteFiles​(Collection<String> paths)
        Delete the specified files
        Specified by:
        deleteFiles in interface Storage
        Parameters:
        paths - files to delete
      • deleteEmptyDirsDown

        public void deleteEmptyDirsDown​(String path)
        Recursively delete all empty directory descendents of the specified directory. The starting path is eligible for deletion.
        Specified by:
        deleteEmptyDirsDown in interface Storage
        Parameters:
        path - starting path
      • deleteEmptyDirsUp

        public 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.
        Specified by:
        deleteEmptyDirsUp in interface Storage
        Parameters:
        path - starting path