Package org.nuxeo.ecm.core.blob
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 aBlobStore.- Since:
- 11.1
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.nuxeo.ecm.core.blob.BlobStore
BlobStore.OptionalOrUnknown<T>
-
-
Field Summary
Fields Modifier and Type Field Description protected StringblobProviderIdstatic charBYTE_RANGE_SEPSeparator between key and byte range (start/end, specified at end of key).protected KeyStrategykeyStrategyprotected Stringname
-
Constructor Summary
Constructors Constructor Description AbstractBlobStore(String blobProviderId, String name, KeyStrategy keyStrategy)AbstractBlobStore(String name, KeyStrategy keyStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancopyBlobIsOptimized(BlobStore sourceStore)Checks if blob copy/move from another blob store to this one can be done efficiently.voiddeleteBlob(BlobContext blobContext)Deletes a blob.protected StringgetBlobKeyReplacement(String key)A key may have been replaced by an async digest computation, use the new one.static ByteRangegetByteRangeFromKey(org.apache.commons.lang3.mutable.MutableObject<String> keyHolder)KeyStrategygetKeyStrategy()Gets the key strategy used by the store.StringgetName()Name used for debugging / tracing.booleanhasVersioning()Whether this blob store has versioning.protected voidlogTrace(String message)protected voidlogTrace(String arrow, String message)protected voidlogTrace(String source, String arrow, String dest, String message)protected voidnotifyAsyncDigest(String key)protected longrandomLong()Returns a random positive long.protected StringrandomString()Returns a random string suitable as a key.static StringsetByteRangeInKey(String key, ByteRange byteRange)protected StringstripBlobKeyPrefix(String key)protected StringstripBlobKeyVersionSuffix(String key)voidtransfer(InputStream in, OutputStream out, KeyStrategy.WriteObserver writeObserver)Copies bytes from an input stream to an output stream, notifying an observer while doing this.voidtransfer(BlobWriteContext blobWriteContext, OutputStream out)Transfers a blob to an output stream, notifying an observer while doing this.voidtransfer(BlobWriteContext blobWriteContext, Path dest)Transfers a blob to a file, notifying an observer while doing this.BlobStoreunwrap()If this blob store wraps another one, returns it, otherwise returns this.booleanuseAsyncDigest()Whether this blob store is configured for async digest computation.StringwriteBlob(BlobContext blobContext)Writes a blob.StringwriteBlob(BlobWriteContext blobWriteContext)Writes a blob.protected StringwriteBlobGeneric(BlobWriteContext blobWriteContext)Writes the blob without using any store-to-store optimization.voidwriteBlobProperties(BlobUpdateContext blobUpdateContext)Sets properties on a blob.protected StringwriteBlobUsingOptimizedCopy(BlobWriteContext blobWriteContext)Tries to do an optimize copy to write this blob.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.ecm.core.blob.BlobStore
clear, copyBlob, copyOrMoveBlob, deleteBlob, exists, getBinaryGarbageCollector, getFile, getStream, hasDefaultStorageClass, readBlob
-
-
-
-
Field Detail
-
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:
- Constant Field Values
-
blobProviderId
protected final String blobProviderId
-
name
protected final String name
-
keyStrategy
protected final KeyStrategy keyStrategy
-
-
Constructor Detail
-
AbstractBlobStore
public AbstractBlobStore(String name, KeyStrategy keyStrategy)
-
AbstractBlobStore
public AbstractBlobStore(String blobProviderId, String name, KeyStrategy keyStrategy)
- Since:
- 11.5
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:BlobStoreName used for debugging / tracing.
-
logTrace
protected void logTrace(String message)
-
hasVersioning
public boolean hasVersioning()
Description copied from interface:BlobStoreWhether 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:
hasVersioningin interfaceBlobStore
-
getKeyStrategy
public KeyStrategy getKeyStrategy()
Description copied from interface:BlobStoreGets the key strategy used by the store.- Specified by:
getKeyStrategyin interfaceBlobStore
-
unwrap
public BlobStore unwrap()
Description copied from interface:BlobStoreIf this blob store wraps another one, returns it, otherwise returns this.
-
writeBlob
public String writeBlob(BlobContext blobContext) throws IOException
Description copied from interface:BlobStoreWrites a blob.- Specified by:
writeBlobin interfaceBlobStore- Parameters:
blobContext- the blob context- Returns:
- the blob key
- Throws:
IOException
-
writeBlob
public String writeBlob(BlobWriteContext blobWriteContext) throws IOException
Description copied from interface:BlobStoreWrites 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:
writeBlobin interfaceBlobStore- 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. Returnsnullif 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:BlobStoreSets properties on a blob.- Specified by:
writeBlobPropertiesin interfaceBlobStore- Parameters:
blobUpdateContext- the blob update context- Throws:
IOException
-
deleteBlob
public void deleteBlob(BlobContext blobContext)
Description copied from interface:BlobStoreDeletes a blob.- Specified by:
deleteBlobin interfaceBlobStore- Parameters:
blobContext- the blob context
-
copyBlobIsOptimized
public boolean copyBlobIsOptimized(BlobStore sourceStore)
Description copied from interface:BlobStoreChecks if blob copy/move from another blob store to this one can be done efficiently.- Specified by:
copyBlobIsOptimizedin interfaceBlobStore- Parameters:
sourceStore- the source store- Returns:
trueif the copy/move can be done efficiently
-
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 observerdest- 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 observerout- 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 streamout- the output streamwriteObserver- the write observer- Throws:
IOException
-
notifyAsyncDigest
protected void notifyAsyncDigest(String key)
-
-