Package org.nuxeo.ecm.core.blob
Class AbstractBlobStore
- java.lang.Object
-
- org.nuxeo.ecm.core.blob.AbstractBlobStore
-
- All Implemented Interfaces:
BlobStore
- Direct Known Subclasses:
CachingBlobStore
,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 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 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.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 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)
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.String
writeBlob(BlobContext blobContext)
Writes a blob.void
writeBlobProperties(BlobUpdateContext blobUpdateContext)
Sets properties on a 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
copyBlob, deleteBlob, getBinaryGarbageCollector, getFile, getStream, readBlob, writeBlob
-
-
-
-
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
-
keyStrategy
protected final KeyStrategy keyStrategy
-
-
Constructor Detail
-
AbstractBlobStore
public AbstractBlobStore(String name, KeyStrategy keyStrategy)
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:BlobStore
Name used for debugging / tracing.
-
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
-
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
-
stripBlobKeyPrefix
protected String stripBlobKeyPrefix(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 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
-
-