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 String
blobProviderId
static char
BYTE_RANGE_SEP
Separator between key and byte range (start/end, specified at end of key).protected KeyStrategy
keyStrategy
protected String
name
-
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 boolean
copyBlobIsOptimized(BlobStore sourceStore)
Checks if blob copy/move from another blob store to this one can be done efficiently.void
deleteBlob(BlobContext blobContext)
Deletes a blob.protected String
getBlobKeyReplacement(String key)
A key may have been replaced by an async digest computation, use the new one.static ByteRange
getByteRangeFromKey(org.apache.commons.lang3.mutable.MutableObject<String> keyHolder)
KeyStrategy
getKeyStrategy()
Gets the key strategy used by the store.String
getName()
Name used for debugging / tracing.boolean
hasVersioning()
Whether this blob store has versioning.protected void
logTrace(String message)
protected void
logTrace(String arrow, String message)
protected void
logTrace(String source, String arrow, String dest, String message)
protected void
notifyAsyncDigest(String key)
protected long
randomLong()
Returns a random positive long.protected String
randomString()
Returns a random string suitable as a key.static String
setByteRangeInKey(String key, ByteRange byteRange)
protected String
stripBlobKeyPrefix(String key)
protected String
stripBlobKeyVersionSuffix(String key)
void
transfer(InputStream in, OutputStream out, KeyStrategy.WriteObserver writeObserver)
Copies bytes from an input stream to an output stream, notifying an observer while doing this.void
transfer(BlobWriteContext blobWriteContext, OutputStream out)
Transfers a blob to an output stream, notifying an observer while doing this.void
transfer(BlobWriteContext blobWriteContext, Path dest)
Transfers a blob to a file, notifying an observer while doing this.BlobStore
unwrap()
If this blob store wraps another one, returns it, otherwise returns this.boolean
useAsyncDigest()
Whether this blob store is configured for async digest computation.String
writeBlob(BlobContext blobContext)
Writes a blob.String
writeBlob(BlobWriteContext blobWriteContext)
Writes a blob.protected String
writeBlobGeneric(BlobWriteContext blobWriteContext)
Writes the blob without using any store-to-store optimization.void
writeBlobProperties(BlobUpdateContext blobUpdateContext)
Sets properties on a blob.protected String
writeBlobUsingOptimizedCopy(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:BlobStore
Name used for debugging / tracing.
-
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 interfaceBlobStore
-
getKeyStrategy
public KeyStrategy getKeyStrategy()
Description copied from interface:BlobStore
Gets the key strategy used by the store.- Specified by:
getKeyStrategy
in interfaceBlobStore
-
unwrap
public BlobStore unwrap()
Description copied from interface:BlobStore
If this blob store wraps another one, returns it, otherwise returns this.
-
writeBlob
public String writeBlob(BlobContext blobContext) throws IOException
Description copied from interface:BlobStore
Writes a blob.- Specified by:
writeBlob
in interfaceBlobStore
- 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 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. Returnsnull
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 interfaceBlobStore
- 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 interfaceBlobStore
- 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 interfaceBlobStore
- Parameters:
sourceStore
- the source store- Returns:
true
if 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)
-
-