Class AbstractBlobStore

java.lang.Object
org.nuxeo.ecm.core.blob.AbstractBlobStore
All Implemented Interfaces:
BlobStore
Direct Known Subclasses:
AzureBlobStore, CachingBlobStore, EmptyBlobStore, GoogleStorageBlobStore, GridFSBlobStore, InMemoryBlobStore, LocalBlobStore, S3BlobStore, TransactionalBlobStore

public abstract class AbstractBlobStore extends Object implements BlobStore
Basic helper implementations for a BlobStore.
Since:
11.1
  • Field Details

    • BYTE_RANGE_SEP

      public static final char BYTE_RANGE_SEP
      Separator between key and byte range (start/end, specified at end of key).

      Used when the blob provider is configured to allow byte ranges.

      See Also:
    • blobProviderId

      protected final String blobProviderId
    • name

      protected final String name
    • keyStrategy

      protected final KeyStrategy keyStrategy
  • Constructor Details

    • AbstractBlobStore

      public AbstractBlobStore(String name, KeyStrategy keyStrategy)
    • AbstractBlobStore

      public AbstractBlobStore(String blobProviderId, String name, KeyStrategy keyStrategy)
      Since:
      11.5
  • Method Details

    • getName

      public String getName()
      Description copied from interface: BlobStore
      Name used for debugging / tracing.
      Specified by:
      getName in interface BlobStore
    • logTrace

      protected void logTrace(String arrow, String message)
    • logTrace

      protected void logTrace(String source, String arrow, String dest, String message)
    • logTrace

      protected void logTrace(String message)
    • hasVersioning

      public boolean hasVersioning()
      Description copied from interface: BlobStore
      Whether this blob store has versioning.

      With versioning, two writes may use the same key. The returned keys will include a different version number to distinguish the writes.

      Specified by:
      hasVersioning in interface BlobStore
    • getKeyStrategy

      public KeyStrategy getKeyStrategy()
      Description copied from interface: BlobStore
      Gets the key strategy used by the store.
      Specified by:
      getKeyStrategy in interface BlobStore
    • unwrap

      public BlobStore unwrap()
      Description copied from interface: BlobStore
      If this blob store wraps another one, returns it, otherwise returns this.
      Specified by:
      unwrap in interface BlobStore
      Returns:
      the lowest-level blob store
    • writeBlob

      public String writeBlob(BlobContext blobContext) throws IOException
      Description copied from interface: BlobStore
      Writes a blob.
      Specified by:
      writeBlob in interface BlobStore
      Parameters:
      blobContext - the blob context
      Returns:
      the blob key
      Throws:
      IOException
    • writeBlob

      public String writeBlob(BlobWriteContext blobWriteContext) throws IOException
      Description copied from interface: BlobStore
      Writes a blob.

      Note that the returned key may be different than the one requested by the BlobWriteContext, if the blob store needs additional version info to retrieve it.

      Specified by:
      writeBlob in interface BlobStore
      Parameters:
      blobWriteContext - the context of the blob write, including the blob
      Returns:
      the key to use to read this blob in the future
      Throws:
      IOException
    • writeBlobGeneric

      protected String writeBlobGeneric(BlobWriteContext blobWriteContext) throws IOException
      Writes the blob without using any store-to-store optimization.
      Throws:
      IOException
      Since:
      11.5
    • writeBlobUsingOptimizedCopy

      protected String writeBlobUsingOptimizedCopy(BlobWriteContext blobWriteContext) throws IOException
      Tries to do an optimize copy to write this blob. Returns null if that's not possible.
      Throws:
      IOException
      Since:
      11.5
    • useAsyncDigest

      public boolean useAsyncDigest()
      Whether this blob store is configured for async digest computation.
      Since:
      11.5
    • writeBlobProperties

      public void writeBlobProperties(BlobUpdateContext blobUpdateContext) throws IOException
      Description copied from interface: BlobStore
      Sets properties on a blob.
      Specified by:
      writeBlobProperties in interface BlobStore
      Parameters:
      blobUpdateContext - the blob update context
      Throws:
      IOException
    • deleteBlob

      public void deleteBlob(BlobContext blobContext)
      Description copied from interface: BlobStore
      Deletes a blob.
      Specified by:
      deleteBlob in interface BlobStore
      Parameters:
      blobContext - the blob context
    • copyBlobIsOptimized

      public boolean copyBlobIsOptimized(BlobStore sourceStore)
      Description copied from interface: BlobStore
      Checks if blob copy/move from another blob store to this one can be done efficiently.
      Specified by:
      copyBlobIsOptimized in interface BlobStore
      Parameters:
      sourceStore - the source store
      Returns:
      true if the copy/move can be done efficiently
    • stripBlobKeyPrefix

      protected String stripBlobKeyPrefix(String key)
    • stripBlobKeyVersionSuffix

      protected String stripBlobKeyVersionSuffix(String key)
    • setByteRangeInKey

      public static String setByteRangeInKey(String key, ByteRange byteRange)
    • getByteRangeFromKey

      public static ByteRange getByteRangeFromKey(org.apache.commons.lang3.mutable.MutableObject<String> keyHolder)
    • randomString

      protected String randomString()
      Returns a random string suitable as a key.
    • randomLong

      protected long randomLong()
      Returns a random positive long.
    • transfer

      public void transfer(BlobWriteContext blobWriteContext, Path dest) throws IOException
      Transfers a blob to a file, notifying an observer while doing this.
      Parameters:
      blobWriteContext - the blob write context, to get the blob stream and write observer
      dest - the destination file
      Throws:
      IOException
    • transfer

      public void transfer(BlobWriteContext blobWriteContext, OutputStream out) throws IOException
      Transfers a blob to an output stream, notifying an observer while doing this.
      Parameters:
      blobWriteContext - the blob write context, to get the blob stream and write observer
      out - the output stream
      Throws:
      IOException
    • transfer

      public void transfer(InputStream in, OutputStream out, KeyStrategy.WriteObserver writeObserver) throws IOException
      Copies bytes from an input stream to an output stream, notifying an observer while doing this.
      Parameters:
      in - the input stream
      out - the output stream
      writeObserver - the write observer
      Throws:
      IOException
    • notifyAsyncDigest

      protected void notifyAsyncDigest(String key)
    • getBlobKeyReplacement

      protected String getBlobKeyReplacement(String key)
      A key may have been replaced by an async digest computation, use the new one.