@ThreadSafe public class FileSystemBinaryStore extends AbstractBinaryStore
BinaryStore
that stores files in a directory on the file system. The store does use file locks to prevent other
processes from concurrently writing the files, and it also uses an internal set of locks to prevent mulitple threads from
simultaneously writing to the persisted files.Modifier and Type | Field and Description |
---|---|
protected static String |
TRASH_DIRECTORY_NAME |
logger, MEDIUM_BUFFER_SIZE
Modifier | Constructor and Description |
---|---|
protected |
FileSystemBinaryStore(File directory) |
Modifier and Type | Method and Description |
---|---|
static FileSystemBinaryStore |
create(File directory) |
protected File |
findFile(File directory,
BinaryKey key,
boolean createParentDirsIfMissing) |
Iterable<BinaryKey> |
getAllBinaryKeys()
Obtain an iterable implementation containing all of the store's binary keys of those binaries that are in use.
|
File |
getDirectory() |
String |
getExtractedText(BinaryValue source)
Returns the extracted text of a binary value, or
null if such text hasn't been stored previously (but the binary
value can be found in the store) |
InputStream |
getInputStream(BinaryKey key)
Get an
InputStream to the binary content with the supplied key. |
protected String |
getStoredMimeType(BinaryValue binaryValue)
Returns the stored mime-type of a binary value.
|
protected void |
initializeStorage(File directory) |
protected void |
markAsUnused(BinaryKey key) |
void |
markAsUnused(Iterable<BinaryKey> keys)
Mark the supplied binary keys as unused, but keep them in quarantine until needed again (at which point they're removed from
quarantine) or until
BinaryStore.removeValuesUnusedLongerThan(long, TimeUnit) is called. |
void |
markAsUsed(Iterable<BinaryKey> keys)
Marks the binary with supplied keys as used.
|
protected void |
moveFileExclusively(File original,
File destination,
BinaryKey key) |
protected void |
pruneEmptyDirectories(File directory,
File removeable)
Remove any empty directories above
removeable but below directory |
protected boolean |
removeAllTrashFilesFor(BinaryKey key) |
void |
removeValuesUnusedLongerThan(long minimumAge,
TimeUnit unit)
Remove binary values that have been
unused for at least the specified amount of time. |
void |
storeExtractedText(BinaryValue source,
String extractedText)
Stores the extracted text of a binary value into this store.
|
protected void |
storeMimeType(BinaryValue binaryValue,
String mimeType)
Stores the given mime-type for a binary value.
|
BinaryValue |
storeValue(InputStream stream,
boolean markAsUnused)
Store the binary value and return the JCR representation.
|
protected void |
touch(File file) |
void |
upgradeTrashContentFormat()
Upgrades the contents of the trash directory to use the new storage format, since MODE-2302.
|
bestBufferSize, detector, extractors, getMimeType, getMinimumBinarySizeInBytes, getText, hasBinary, setMimeTypeDetector, setMinimumBinarySizeInBytes, setTextExtractors, shutdown, start, storeValue
protected static final String TRASH_DIRECTORY_NAME
protected FileSystemBinaryStore(File directory)
public static FileSystemBinaryStore create(File directory)
public File getDirectory()
public BinaryValue storeValue(InputStream stream, boolean markAsUnused) throws BinaryStoreException
BinaryStore
stream
- the stream containing the binary content to be stored; may not be nullmarkAsUnused
- a boolean
which indicates if the binary will be stored as unused or not. Binaries used from
normal sessions (via properties) will normally be stored as unused and they will be marked as used only on tx commit.BinaryStoreException
- if there any unexpected problemprotected final void moveFileExclusively(File original, File destination, BinaryKey key) throws BinaryStoreException
BinaryStoreException
protected final File findFile(File directory, BinaryKey key, boolean createParentDirsIfMissing) throws BinaryStoreException
BinaryStoreException
public InputStream getInputStream(BinaryKey key) throws BinaryStoreException
BinaryStore
InputStream
to the binary content with the supplied key. The input stream will be returned as long as
the binary value has not been removed, so expired binary values should be included here as well.key
- the key to the binary content; never nullnever null
BinaryStoreException
- if there is a problem reading the content from the store or if a valid, non-null
InputStream
cannot be returned for the given key.protected void initializeStorage(File directory) throws BinaryStoreException
BinaryStoreException
public void markAsUsed(Iterable<BinaryKey> keys) throws BinaryStoreException
BinaryStore
keys
- a BinaryKey
Iterable
, may not be nullBinaryStoreException
- if anything unexpected fails.public void upgradeTrashContentFormat() throws BinaryStoreException
BinaryStoreException
- if anything unexpected failsprotected boolean removeAllTrashFilesFor(BinaryKey key) throws BinaryStoreException
BinaryStoreException
public void markAsUnused(Iterable<BinaryKey> keys) throws BinaryStoreException
BinaryStore
BinaryStore.removeValuesUnusedLongerThan(long, TimeUnit)
is called. This method ignores any keys for
values not stored within this store.keys
- the keys for the binary values that are no longer neededBinaryStoreException
- if there is a problem marking any of the supplied binary values as unusedprotected void markAsUnused(BinaryKey key) throws BinaryStoreException
BinaryStoreException
protected void touch(File file) throws BinaryStoreException
BinaryStoreException
protected void pruneEmptyDirectories(File directory, File removeable)
removeable
but below directory
directory
- the top-level directory to keep; may not be null and must be an ancestor of removeable
removeable
- the file or directory above which any empty directories can be removed; may not be nullpublic void removeValuesUnusedLongerThan(long minimumAge, TimeUnit unit) throws BinaryStoreException
BinaryStore
unused
for at least the specified amount of time.minimumAge
- the minimum time that a binary value has been unused
before it can be
removed; must be non-negativeunit
- the time unit for the minimum age; may not be nullBinaryStoreException
- if there is a problem removing the unused valuespublic String getExtractedText(BinaryValue source) throws BinaryStoreException
AbstractBinaryStore
null
if such text hasn't been stored previously (but the binary
value can be found in the store)getExtractedText
in class AbstractBinaryStore
source
- a non-null
BinaryValue
instance from which the text was extractedString
representing the extracted text, or null
if such text hasn't been stored in this store
previously.BinaryStoreException
- if the binary value cannot be found in the store.public void storeExtractedText(BinaryValue source, String extractedText) throws BinaryStoreException
AbstractBinaryStore
storeExtractedText
in class AbstractBinaryStore
source
- a non-null
BinaryValue
instance from which the text was extractedextractedText
- a non-null
and non-blank
string representing the extracted textBinaryStoreException
- if the operation fails or if the extracted text cannot be stored for the given binary value
(regardless of the reason)protected String getStoredMimeType(BinaryValue binaryValue) throws BinaryStoreException
AbstractBinaryStore
getStoredMimeType
in class AbstractBinaryStore
binaryValue
- a non-null
BinaryValue
String
if a stored mimetype exists, or null
if such a value doesn't exist yet.BinaryStoreException
- if there's a problem accessing the binary store or if the binary value cannot be found in the
storeprotected void storeMimeType(BinaryValue binaryValue, String mimeType) throws BinaryStoreException
AbstractBinaryStore
storeMimeType
in class AbstractBinaryStore
binaryValue
- a non-null
BinaryValue
mimeType
- a non-empty String
BinaryStoreException
- if there's a problem accessing the binary storepublic Iterable<BinaryKey> getAllBinaryKeys() throws BinaryStoreException
BinaryStore
BinaryKey
s only as the iterator is used.BinaryStoreException
- if anything unexpected happens.Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.