Interface BlobContainer

  • All Known Implementing Classes:
    AbstractBlobContainer, FsBlobContainer

    public interface BlobContainer
    An interface for managing a repository of blob entries, where each blob entry is just a named group of bytes.
    • Method Summary

      Modifier and Type Method Description
      boolean blobExists​(java.lang.String blobName)
      Tests whether a blob with the given blob name exists in the container.
      void deleteBlob​(java.lang.String blobName)
      Deletes a blob with giving name, if the blob exists.
      default void deleteBlobIgnoringIfNotExists​(java.lang.String blobName)
      Deletes a blob with giving name, ignoring if the blob does not exist.
      java.util.Map<java.lang.String,​BlobMetaData> listBlobs()
      Lists all blobs in the container.
      java.util.Map<java.lang.String,​BlobMetaData> listBlobsByPrefix​(java.lang.String blobNamePrefix)
      Lists all blobs in the container that match the specified prefix.
      BlobPath path()
      Gets the BlobPath that defines the implementation specific paths to where the blobs are contained.
      java.io.InputStream readBlob​(java.lang.String blobName)
      Creates a new InputStream for the given blob name.
      void writeBlob​(java.lang.String blobName, java.io.InputStream inputStream, long blobSize, boolean failIfAlreadyExists)
      Reads blob content from the input stream and writes it to the container in a new blob with the given name.
      default void writeBlobAtomic​(java.lang.String blobName, java.io.InputStream inputStream, long blobSize, boolean failIfAlreadyExists)
      Reads blob content from the input stream and writes it to the container in a new blob with the given name, using an atomic write operation if the implementation supports it.
    • Method Detail

      • path

        BlobPath path()
        Gets the BlobPath that defines the implementation specific paths to where the blobs are contained.
        Returns:
        the BlobPath where the blobs are contained
      • blobExists

        boolean blobExists​(java.lang.String blobName)
        Tests whether a blob with the given blob name exists in the container.
        Parameters:
        blobName - The name of the blob whose existence is to be determined.
        Returns:
        true if a blob exists in the BlobContainer with the given name, and false otherwise.
      • readBlob

        java.io.InputStream readBlob​(java.lang.String blobName)
                              throws java.io.IOException
        Creates a new InputStream for the given blob name.
        Parameters:
        blobName - The name of the blob to get an InputStream for.
        Returns:
        The InputStream to read the blob.
        Throws:
        java.nio.file.NoSuchFileException - if the blob does not exist
        java.io.IOException - if the blob can not be read.
      • writeBlob

        void writeBlob​(java.lang.String blobName,
                       java.io.InputStream inputStream,
                       long blobSize,
                       boolean failIfAlreadyExists)
                throws java.io.IOException
        Reads blob content from the input stream and writes it to the container in a new blob with the given name. This method assumes the container does not already contain a blob of the same blobName. If a blob by the same name already exists, the operation will fail and an IOException will be thrown.
        Parameters:
        blobName - The name of the blob to write the contents of the input stream to.
        inputStream - The input stream from which to retrieve the bytes to write to the blob.
        blobSize - The size of the blob to be written, in bytes. It is implementation dependent whether this value is used in writing the blob to the repository.
        failIfAlreadyExists - whether to throw a FileAlreadyExistsException if the given blob already exists
        Throws:
        java.nio.file.FileAlreadyExistsException - if failIfAlreadyExists is true and a blob by the same name already exists
        java.io.IOException - if the input stream could not be read, or the target blob could not be written to.
      • writeBlobAtomic

        default void writeBlobAtomic​(java.lang.String blobName,
                                     java.io.InputStream inputStream,
                                     long blobSize,
                                     boolean failIfAlreadyExists)
                              throws java.io.IOException
        Reads blob content from the input stream and writes it to the container in a new blob with the given name, using an atomic write operation if the implementation supports it. When the BlobContainer implementation does not provide a specific implementation of writeBlobAtomic(String, InputStream, long), then the writeBlob(String, InputStream, long, boolean) method is used. This method assumes the container does not already contain a blob of the same blobName. If a blob by the same name already exists, the operation will fail and an IOException will be thrown.
        Parameters:
        blobName - The name of the blob to write the contents of the input stream to.
        inputStream - The input stream from which to retrieve the bytes to write to the blob.
        blobSize - The size of the blob to be written, in bytes. It is implementation dependent whether this value is used in writing the blob to the repository.
        failIfAlreadyExists - whether to throw a FileAlreadyExistsException if the given blob already exists
        Throws:
        java.nio.file.FileAlreadyExistsException - if failIfAlreadyExists is true and a blob by the same name already exists
        java.io.IOException - if the input stream could not be read, or the target blob could not be written to.
      • deleteBlob

        void deleteBlob​(java.lang.String blobName)
                 throws java.io.IOException
        Deletes a blob with giving name, if the blob exists. If the blob does not exist, this method throws a NoSuchFileException.
        Parameters:
        blobName - The name of the blob to delete.
        Throws:
        java.nio.file.NoSuchFileException - if the blob does not exist
        java.io.IOException - if the blob exists but could not be deleted.
      • deleteBlobIgnoringIfNotExists

        default void deleteBlobIgnoringIfNotExists​(java.lang.String blobName)
                                            throws java.io.IOException
        Deletes a blob with giving name, ignoring if the blob does not exist.
        Parameters:
        blobName - The name of the blob to delete.
        Throws:
        java.io.IOException - if the blob exists but could not be deleted.
      • listBlobs

        java.util.Map<java.lang.String,​BlobMetaData> listBlobs()
                                                              throws java.io.IOException
        Lists all blobs in the container.
        Returns:
        A map of all the blobs in the container. The keys in the map are the names of the blobs and the values are BlobMetaData, containing basic information about each blob.
        Throws:
        java.io.IOException - if there were any failures in reading from the blob container.
      • listBlobsByPrefix

        java.util.Map<java.lang.String,​BlobMetaData> listBlobsByPrefix​(java.lang.String blobNamePrefix)
                                                                      throws java.io.IOException
        Lists all blobs in the container that match the specified prefix.
        Parameters:
        blobNamePrefix - The prefix to match against blob names in the container.
        Returns:
        A map of the matching blobs in the container. The keys in the map are the names of the blobs and the values are BlobMetaData, containing basic information about each blob.
        Throws:
        java.io.IOException - if there were any failures in reading from the blob container.