@ThreadSafe public abstract class AbstractBinaryStore extends Object implements BinaryStore
BinaryStore
, with common functionality needed by implementation classes.Modifier and Type | Field and Description |
---|---|
protected Logger |
logger |
protected static int |
MEDIUM_BUFFER_SIZE |
Constructor and Description |
---|
AbstractBinaryStore() |
Modifier and Type | Method and Description |
---|---|
static int |
bestBufferSize(long fileSize)
Given a number of bytes representing the length of a file, returns the optimum size for a buffer that should be used
when reading/working with that file
|
protected MimeTypeDetector |
detector()
Get the MIME type detector that can be used to find the MIME type for binary content
|
protected TextExtractors |
extractors()
Get the text extractor that can be used to extract text by this store.
|
abstract 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) |
String |
getMimeType(BinaryValue binary,
String name)
Get the MIME type for this binary value, never
null . |
long |
getMinimumBinarySizeInBytes()
Get the minimum number of bytes that a binary value must contain before it can be stored in the binary store.
|
protected abstract String |
getStoredMimeType(BinaryValue binaryValue)
Returns the stored mime-type of a binary value.
|
String |
getText(BinaryValue binary)
Get the text that can be extracted from this binary content.
|
boolean |
hasBinary(BinaryKey key)
Searches for a binary which has the given key in this store.
|
void |
setMimeTypeDetector(MimeTypeDetector mimeTypeDetector)
Set the MIME type detector that can be used for determining the MIME type for binary content.
|
void |
setMinimumBinarySizeInBytes(long minSizeInBytes)
Set the minimum number of bytes that a binary value must contain before it can be stored in the binary store.
|
void |
setTextExtractors(TextExtractors textExtractors)
Set the text extractor that can be used for extracting text from binary content.
|
void |
shutdown()
Shuts down the store.
|
void |
start()
Initialize the store and get ready for use.
|
abstract void |
storeExtractedText(BinaryValue source,
String extractedText)
Stores the extracted text of a binary value into this store.
|
protected abstract void |
storeMimeType(BinaryValue binaryValue,
String mimeType)
Stores the given mime-type for a binary value.
|
BinaryValue |
storeValue(InputStream stream,
String hint,
boolean markAsUnused)
Store the binary value and return the JCR representation.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAllBinaryKeys, getInputStream, markAsUnused, markAsUsed, removeValuesUnusedLongerThan, storeValue
protected static final int MEDIUM_BUFFER_SIZE
protected final Logger logger
public static int bestBufferSize(long fileSize)
fileSize
- the size of a file, in bytespublic long getMinimumBinarySizeInBytes()
BinaryStore
getMinimumBinarySizeInBytes
in interface BinaryStore
public void setMinimumBinarySizeInBytes(long minSizeInBytes)
BinaryStore
setMinimumBinarySizeInBytes
in interface BinaryStore
minSizeInBytes
- the minimum number of bytes for a stored binary value; may not be negativepublic void setTextExtractors(TextExtractors textExtractors)
BinaryStore
setTextExtractors
in interface BinaryStore
textExtractors
- a non-null TextExtractors
instancepublic void setMimeTypeDetector(MimeTypeDetector mimeTypeDetector)
BinaryStore
setMimeTypeDetector
in interface BinaryStore
mimeTypeDetector
- the detector; may not be null
public final String getText(BinaryValue binary) throws BinaryStoreException
BinaryStore
null
If extraction is enabled, this method may block until a text extractor has finished extracting the text.
If there are any problems either with the binary value or during the extraction process, the exception will be logged and
null
is returned
AbstractBinaryStore
should be enough and any custom BinaryStore
implementations aren't expected to implement this.getText
in interface BinaryStore
binary
- the binary content; may not be nullBinaryStoreException
- if the binary content could not be accessed or if the given binary value cannot be found
within the store.public String getMimeType(BinaryValue binary, String name) throws IOException, RepositoryException
BinaryStore
null
.
If the store has never determined the mime-type of the given binary and the binary can be located in the store, it will
attempt to determine it via the configured detectors
and store it.
getMimeType
in interface BinaryStore
binary
- the binary content; may not be nullname
- the name of the content, useful for determining the MIME type; may be null if not knownnull
if none of the detectors can
determine it.IOException
- if there is a problem reading the binary contentBinaryStoreException
- if the binary value cannot be found in the storeRepositoryException
- if any other error occurs.public boolean hasBinary(BinaryKey key)
BinaryStore
true
as long the binary
is still present physically, regardless of any "trash" semantics.hasBinary
in interface BinaryStore
key
- a non-null BinaryKey
instancetrue
if a binary with this key exists in this store, false
otherwise.protected abstract String getStoredMimeType(BinaryValue binaryValue) throws BinaryStoreException
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 abstract void storeMimeType(BinaryValue binaryValue, String mimeType) throws BinaryStoreException
binaryValue
- a non-null
BinaryValue
mimeType
- a non-empty String
BinaryStoreException
- if there's a problem accessing the binary storepublic abstract void storeExtractedText(BinaryValue source, String extractedText) throws BinaryStoreException
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)public abstract String getExtractedText(BinaryValue source) throws BinaryStoreException
null
if such text hasn't been stored previously (but the binary
value can be found in the store)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.protected final TextExtractors extractors()
protected final MimeTypeDetector detector()
public BinaryValue storeValue(InputStream stream, String hint, boolean markAsUnused) throws BinaryStoreException
BinaryStore
storeValue
in interface BinaryStore
stream
- the stream containing the binary content to be stored; may not be nullhint
- a hint that the BinaryStore may use to make storage decisions about this input streammarkAsUnused
- 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 problempublic void start()
BinaryStore
start
in interface BinaryStore
public void shutdown()
BinaryStore
shutdown
in interface BinaryStore
Copyright © 2008–2016 JBoss, a division of Red Hat. All rights reserved.