Class DataStoreBlobStore

    • Field Detail

      • delegate

        protected final DataStore delegate
      • cache

        protected final org.apache.jackrabbit.guava.common.cache.LoadingCache<java.lang.String,​byte[]> cache
    • Constructor Detail

      • DataStoreBlobStore

        public DataStoreBlobStore​(DataStore delegate)
      • DataStoreBlobStore

        public DataStoreBlobStore​(DataStore delegate,
                                  boolean encodeLengthInId)
      • DataStoreBlobStore

        public DataStoreBlobStore​(DataStore delegate,
                                  boolean encodeLengthInId,
                                  int cacheSizeInMB)
    • Method Detail

      • writeBlob

        public java.lang.String writeBlob​(java.io.InputStream stream)
                                   throws java.io.IOException
        Description copied from interface: BlobStore
        Write a blob from an input stream. This method closes the input stream.
        Specified by:
        writeBlob in interface BlobStore
        Parameters:
        stream - the input stream
        Returns:
        the blob id
        Throws:
        java.io.IOException
      • writeBlob

        public java.lang.String writeBlob​(java.io.InputStream stream,
                                          BlobOptions options)
                                   throws java.io.IOException
        Description copied from interface: BlobStore
        Write a blob from an input stream with specified options. This method closes the input stream.
        Specified by:
        writeBlob in interface BlobStore
        Parameters:
        stream - the input stream to write
        options - the options to use
        Returns:
        Throws:
        java.io.IOException
      • readBlob

        public int readBlob​(java.lang.String encodedBlobId,
                            long pos,
                            byte[] buff,
                            int off,
                            int length)
                     throws java.io.IOException
        Description copied from interface: BlobStore
        Read a number of bytes from a blob.
        Specified by:
        readBlob in interface BlobStore
        Parameters:
        encodedBlobId - the blob id
        pos - the position within the blob
        buff - the target byte array
        off - the offset within the target array
        length - the number of bytes to read
        Returns:
        the number of bytes read
        Throws:
        java.io.IOException
      • getBlobLength

        public long getBlobLength​(java.lang.String encodedBlobId)
                           throws java.io.IOException
        Description copied from interface: BlobStore
        Get the length of the blob.
        Specified by:
        getBlobLength in interface BlobStore
        Parameters:
        encodedBlobId - the blob id
        Returns:
        the length
        Throws:
        java.io.IOException
      • getBlobId

        public java.lang.String getBlobId​(@NotNull
                                          @NotNull java.lang.String reference)
        Description copied from interface: BlobStore
        Returns the blobId that referred by the given binary reference. Returns null if the reference is invalid, for example if it points to a blob that does not exist.
        Specified by:
        getBlobId in interface BlobStore
        Parameters:
        reference - binary reference
        Returns:
        matching blobId, or null
      • getReference

        public java.lang.String getReference​(@NotNull
                                             @NotNull java.lang.String encodedBlobId)
        Description copied from interface: BlobStore
        Returns a secure reference to blob referred by blobid, or null if no such reference is available.
        Specified by:
        getReference in interface BlobStore
        Parameters:
        encodedBlobId - blobId referring the blob for which reference is required
        Returns:
        binary reference, or null
      • getInputStream

        public java.io.InputStream getInputStream​(java.lang.String encodedBlobId)
                                           throws java.io.IOException
        Description copied from interface: BlobStore
        Returns a new stream for given blobId. The streams returned from multiple calls to this method are byte wise equals. That is, subsequent calls to read return the same sequence of bytes as long as neither call throws an exception.
        Specified by:
        getInputStream in interface BlobStore
        Parameters:
        encodedBlobId - the blob id
        Returns:
        a new stream for given blobId
        Throws:
        java.io.IOException
      • setBlockSize

        public void setBlockSize​(int x)
        Description copied from interface: GarbageCollectableBlobStore
        Set the block size used by this blob store, if the blob store splits binaries into blocks. If not, this setting is ignored.
        Specified by:
        setBlockSize in interface GarbageCollectableBlobStore
        Parameters:
        x - the block size in bytes.
      • writeBlob

        public java.lang.String writeBlob​(java.lang.String tempFileName)
                                   throws java.io.IOException
        Description copied from interface: GarbageCollectableBlobStore
        Write a blob from a temporary file. The temporary file is removed afterwards. A file based blob stores might simply rename the file, so that no additional writes are necessary.
        Specified by:
        writeBlob in interface GarbageCollectableBlobStore
        Parameters:
        tempFileName - the temporary file name
        Returns:
        the blob id
        Throws:
        java.io.IOException
      • getAllChunkIds

        public java.util.Iterator<java.lang.String> getAllChunkIds​(long maxLastModifiedTime)
                                                            throws java.lang.Exception
        Description copied from interface: GarbageCollectableBlobStore
        Gets all the identifiers.
        Specified by:
        getAllChunkIds in interface GarbageCollectableBlobStore
        Parameters:
        maxLastModifiedTime - the max last modified time to consider for retrieval, with the special value '0' meaning no filtering by time
        Returns:
        the identifiers
        Throws:
        java.lang.Exception - the exception
      • deleteChunks

        public boolean deleteChunks​(java.util.List<java.lang.String> chunkIds,
                                    long maxLastModifiedTime)
                             throws java.lang.Exception
        Description copied from interface: GarbageCollectableBlobStore
        Deletes the blobs with the given ids.
        Specified by:
        deleteChunks in interface GarbageCollectableBlobStore
        Parameters:
        chunkIds - the chunk ids
        maxLastModifiedTime - the max last modified time to consider for retrieval, with the special value '0' meaning no filtering by time
        Returns:
        true, if successful
        Throws:
        java.lang.Exception - the exception
      • countDeleteChunks

        public long countDeleteChunks​(java.util.List<java.lang.String> chunkIds,
                                      long maxLastModifiedTime)
                               throws java.lang.Exception
        Description copied from interface: GarbageCollectableBlobStore
        Deletes the blobs with the given ids.
        Specified by:
        countDeleteChunks in interface GarbageCollectableBlobStore
        Parameters:
        chunkIds - the chunk ids
        maxLastModifiedTime - the max last modified time to consider for retrieval, with the special value '0' meaning no filtering by time
        Returns:
        long the count of successful deletions
        Throws:
        java.lang.Exception - the exception
      • resolveChunks

        public java.util.Iterator<java.lang.String> resolveChunks​(java.lang.String blobId)
                                                           throws java.io.IOException
        Description copied from interface: GarbageCollectableBlobStore
        Resolve chunks stored in the blob store from the given Id. This will not return any chunks stored in-line in the id.
        Specified by:
        resolveChunks in interface GarbageCollectableBlobStore
        Parameters:
        blobId - the blob id
        Returns:
        the iterator
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
      • getMetadataRecord

        public DataRecord getMetadataRecord​(java.lang.String name)
        Description copied from interface: SharedDataStore
        Retrieves the metadata record with the given name
        Specified by:
        getMetadataRecord in interface SharedDataStore
        Parameters:
        name - the name of the record
        Returns:
      • metadataRecordExists

        public boolean metadataRecordExists​(java.lang.String name)
        Description copied from interface: SharedDataStore
        Checks if the metadata record with the name exists
        Specified by:
        metadataRecordExists in interface SharedDataStore
        Returns:
      • deleteMetadataRecord

        public boolean deleteMetadataRecord​(java.lang.String name)
        Description copied from interface: SharedDataStore
        Deletes the root record represented by the given parameters.
        Specified by:
        deleteMetadataRecord in interface SharedDataStore
        Parameters:
        name - the name of the root record
        Returns:
        success/failure
      • deleteAllMetadataRecords

        public void deleteAllMetadataRecords​(java.lang.String prefix)
        Description copied from interface: SharedDataStore
        Deletes all records matching the given prefix.
        Specified by:
        deleteAllMetadataRecords in interface SharedDataStore
        Parameters:
        prefix - metadata type identifier
      • getRepositoryId

        public java.lang.String getRepositoryId()
        Description copied from interface: SharedDataStore
        Returns the repository id (identifier for the repository in the DataStore)
        Specified by:
        getRepositoryId in interface SharedDataStore
        Returns:
        repository id
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getDataStore

        public DataStore getDataStore()
      • getCacheStats

        public CacheStats getCacheStats()
      • setMaxCachedBinarySize

        public void setMaxCachedBinarySize​(int maxCachedBinarySize)
      • getStream

        protected java.io.InputStream getStream​(java.lang.String blobId)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • extractBlobId

        protected java.lang.String extractBlobId​(java.lang.String encodedBlobId)
      • initiateBlobUpload

        @Nullable
        public @Nullable BlobUpload initiateBlobUpload​(long maxUploadSizeInBytes,
                                                       int maxNumberOfURIs)
                                                throws java.lang.IllegalArgumentException
        Description copied from interface: BlobAccessProvider
        Begin a transaction to perform a direct blob upload to a storage location. This method will throw IllegalArgumentException if no valid upload can be arranged with the arguments specified. E.g. the max upload size specified divided by the number of URIs requested indicates the minimum size of each upload. If that size exceeds the maximum upload size supported by the service provider, IllegalArgumentException is thrown.

        Each service provider has specific limitations with regard to maximum upload sizes, maximum overall blob sizes, numbers of URIs in multi-part uploads, etc. which can lead to IllegalArgumentException being thrown. You should consult the documentation for your specific service provider for details.

        Beyond service provider limitations, the implementation may also choose to enforce its own limitations and may throw this exception based on those limitations. Configuration may also be used to set limitations so this exception may be thrown when configuration parameters are exceeded.

        Specified by:
        initiateBlobUpload in interface BlobAccessProvider
        Parameters:
        maxUploadSizeInBytes - the largest size of the blob to be uploaded, in bytes, based on the caller's best guess. If the actual size of the file to be uploaded is known, that value should be used.
        maxNumberOfURIs - the maximum number of URIs the client is able to accept. If the client does not support multi-part uploading, this value should be 1. Note that the implementing class is not required to support multi-part uploading so it may return only a single upload URI regardless of the value passed in for this parameter. If the client is able to accept any number of URIs, a value of -1 may be passed in to indicate that the implementation is free to return as many URIs as it desires.
        Returns:
        A BlobUpload referencing this direct upload, or null if the underlying implementation doesn't support direct uploading.
        Throws:
        java.lang.IllegalArgumentException - if maxUploadSizeInBytes is not a positive value, or if maxNumberOfURIs is not either a positive value or -1, or if the upload cannot be completed as requested, due to a mismatch between the request parameters and the capabilities of the service provider or the implementation.
      • initiateBlobUpload

        @Nullable
        public @Nullable BlobUpload initiateBlobUpload​(long maxUploadSizeInBytes,
                                                       int maxNumberOfURIs,
                                                       @NotNull
                                                       @NotNull BlobUploadOptions options)
                                                throws java.lang.IllegalArgumentException
        Description copied from interface: BlobAccessProvider
        Begin a transaction to perform a direct blob upload to a storage location. This method will throw IllegalArgumentException if no valid upload can be arranged with the arguments specified. E.g. the max upload size specified divided by the number of URIs requested indicates the minimum size of each upload. If that size exceeds the maximum upload size supported by the service provider, IllegalArgumentException is thrown.

        Each service provider has specific limitations with regard to maximum upload sizes, maximum overall blob sizes, numbers of URIs in multi-part uploads, etc. which can lead to IllegalArgumentException being thrown. You should consult the documentation for your specific service provider for details.

        Beyond service provider limitations, the implementation may also choose to enforce its own limitations and may throw this exception based on those limitations. Configuration may also be used to set limitations so this exception may be thrown when configuration parameters are exceeded.

        Specified by:
        initiateBlobUpload in interface BlobAccessProvider
        Parameters:
        maxUploadSizeInBytes - the largest size of the blob to be uploaded, in bytes, based on the caller's best guess. If the actual size of the file to be uploaded is known, that value should be used.
        maxNumberOfURIs - the maximum number of URIs the client is able to accept. If the client does not support multi-part uploading, this value should be 1. Note that the implementing class is not required to support multi-part uploading so it may return only a single upload URI regardless of the value passed in for this parameter. If the client is able to accept any number of URIs, a value of -1 may be passed in to indicate that the implementation is free to return as many URIs as it desires.
        options - an instance of BlobUploadOptions which allows the caller to specify any desired upload URI options.
        Returns:
        A BlobUpload referencing this direct upload, or null if the underlying implementation doesn't support direct uploading.
        Throws:
        java.lang.IllegalArgumentException - if maxUploadSizeInBytes is not a positive value, or if maxNumberOfURIs is not either a positive value or -1, or if the upload cannot be completed as requested, due to a mismatch between the request parameters and the capabilities of the service provider or the implementation.
      • completeBlobUpload

        @Nullable
        public @Nullable Blob completeBlobUpload​(@NotNull
                                                 @NotNull java.lang.String uploadToken)
                                          throws java.lang.IllegalArgumentException
        Description copied from interface: BlobAccessProvider
        Complete a transaction for uploading a blob to a storage location via direct blob upload.

        This requires an uploadToken that can be obtained from the returned BlobUpload from a previous call to BlobAccessProvider.initiateBlobUpload(long, int). This token is required to complete the transaction for an upload to be valid and complete. The token includes encoded data about the transaction and may include a signature that will be verified by the implementation.

        Specified by:
        completeBlobUpload in interface BlobAccessProvider
        Parameters:
        uploadToken - the upload token from a BlobUpload object returned from a previous call to BlobAccessProvider.initiateBlobUpload(long, int).
        Returns:
        The Blob that was created, or null if the object could not be created.
        Throws:
        java.lang.IllegalArgumentException - if the uploadToken is null, empty, or cannot be parsed or is otherwise invalid, e.g. if the included signature does not match.
      • getDownloadURI

        @Nullable
        public @Nullable java.net.URI getDownloadURI​(@NotNull
                                                     @NotNull Blob blob,
                                                     @NotNull
                                                     @NotNull BlobDownloadOptions downloadOptions)
        Description copied from interface: BlobAccessProvider
        Obtain a download URI for a Blob. This is usually a signed URI that can be used to directly download the blob corresponding to the provided Blob.

        A caller must specify a BlobDownloadOptions instance. The implementation will attempt to apply the specified downloadOptions to the subsequent download. For example, if the caller knows that the URI refers to a specific type of content, the caller can specify that content type by setting it in the downloadOptions. The caller may also use a default instance obtained via BlobDownloadOptions.DEFAULT in which case the caller is indicating that the default behavior of the service provider is acceptable.

        Specified by:
        getDownloadURI in interface BlobAccessProvider
        Parameters:
        blob - The Blob to be downloaded.
        downloadOptions - A BlobDownloadOptions instance that specifies any download options to be used for the download URI.
        Returns:
        A URI to download the blob directly or null if the blob cannot be downloaded directly.