public abstract class CachingBinaryManager extends AbstractBinaryManager
BinaryManager
that uses a cache for its files
because fetching them is expensive.
Initialization of the BinaryManager
must call
initializeCache(java.io.File, long, org.nuxeo.ecm.core.storage.binary.FileStorage)
from the initialize(org.nuxeo.ecm.core.storage.binary.BinaryManagerDescriptor)
method.
AbstractBinaryManager.NullBinaryScrambler, AbstractBinaryManager.ScrambledBinary, AbstractBinaryManager.ScrambledFileInputStream, AbstractBinaryManager.ScrambledStreamSource
Modifier and Type | Field and Description |
---|---|
FileCache |
fileCache |
DEFAULT_DEPTH, DEFAULT_DIGEST, MAX_BUF_SIZE, MIN_BUF_SIZE
Constructor and Description |
---|
CachingBinaryManager() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the binary manager and releases all resources and temporary
objects held by it.
|
Binary |
getBinary(InputStream in)
Saves the given input stream into a
Binary . |
Binary |
getBinary(String digest)
Returns a
Binary corresponding to the given digest. |
File |
getFile(String digest)
Gets a file from cache or storage.
|
Long |
getLength(String digest)
Gets a file length from cache or storage.
|
void |
initialize(BinaryManagerDescriptor binaryManagerDescriptor)
Initializer.
|
void |
initializeCache(File dir,
long maxSize,
FileStorage fileStorage)
Initialize the cache.
|
void |
initializeCache(String cacheSizeStr,
FileStorage fileStorage)
Initialize the cache.
|
getGarbageCollector, toHexString
public FileCache fileCache
public void initialize(BinaryManagerDescriptor binaryManagerDescriptor) throws IOException
BinaryManager
initialize
in interface BinaryManager
initialize
in class AbstractBinaryManager
IOException
public void initializeCache(File dir, long maxSize, FileStorage fileStorage)
dir
- the directory to use to store cached filesmaxSize
- the maximum size of the cache (in bytes)fileStorage
- the file storage mechanism to use to store and fetch
filespublic void initializeCache(String cacheSizeStr, FileStorage fileStorage) throws IOException
cacheSizeStr
- the maximum size of the cache (as a String)fileStorage
- the file storage mechanism to use to store and fetch
filesIOException
initializeCache(File, long, FileStorage)
,
SizeUtils.parseSizeInBytes(String)
public void close()
BinaryManager
public Binary getBinary(InputStream in) throws IOException
BinaryManager
Binary
.
Returns a Binary
representing the stream. The Binary
includes a digest that is a sufficient representation to persist it.
The stream is closed after use.
getBinary
in interface BinaryManager
getBinary
in class AbstractBinaryManager
in
- the input streamIOException
public Binary getBinary(String digest)
BinaryManager
Binary
corresponding to the given digest.
A null
is returned if the digest could not be found.
getBinary
in interface BinaryManager
getBinary
in class AbstractBinaryManager
digest
- the digest, or null
public File getFile(String digest) throws IOException
Used by LazyBinary
.
IOException
public Long getLength(String digest) throws IOException
Use by LazyBinary
.
IOException
Copyright © 2014 Nuxeo SA. All rights reserved.