org.modeshape.jcr.value.binary

## Class AbstractBinaryStore

- java.lang.Object
- - org.modeshape.jcr.value.binary.AbstractBinaryStore

- All Implemented Interfaces:
    BinaryStore
  Direct Known Subclasses:
    CassandraBinaryStore, DatabaseBinaryStore, FileSystemBinaryStore, InfinispanBinaryStore, MongodbBinaryStore

      @ThreadSafe
      public abstract class AbstractBinaryStore
      extends Object
      implements BinaryStore

  An abstract class for a `BinaryStore`, with common functionality needed by implementation classes.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected Logger` | `logger`
    `protected static int` | `MEDIUM_BUFFER_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractBinaryStore()`

  - ### Method Summary

    Methods
    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)` Store the binary value and return the JCR representation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.modeshape.jcr.value.binary.BinaryStore

      `getAllBinaryKeys, getInputStream, markAsUnused, removeValuesUnusedLongerThan, storeValue`

- - ### Field Detail

    - #### MEDIUM_BUFFER_SIZE

          protected static final int MEDIUM_BUFFER_SIZE

      See Also:
        Constant Field Values

    - #### logger

          protected Logger logger

  - ### Constructor Detail

    - #### AbstractBinaryStore

          public AbstractBinaryStore()

  - ### Method Detail

    - #### bestBufferSize

          public 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
      Parameters:
        `fileSize` - the size of a file, in bytes
      Returns:
        the size of a read/write buffer

    - #### getMinimumBinarySizeInBytes

          public long getMinimumBinarySizeInBytes()

      Description copied from interface: `BinaryStore`
      Get the minimum number of bytes that a binary value must contain before it can be stored in the binary store.
      Specified by:
        `getMinimumBinarySizeInBytes` in interface `BinaryStore`
      Returns:
        the minimum number of bytes for a stored binary value; never negative

    - #### setMinimumBinarySizeInBytes

          public void setMinimumBinarySizeInBytes(long minSizeInBytes)

      Description copied from interface: `BinaryStore`
      Set the minimum number of bytes that a binary value must contain before it can be stored in the binary store.
      Specified by:
        `setMinimumBinarySizeInBytes` in interface `BinaryStore`
      Parameters:
        `minSizeInBytes` - the minimum number of bytes for a stored binary value; may not be negative

    - #### setTextExtractors

          public void setTextExtractors(TextExtractors textExtractors)

      Description copied from interface: `BinaryStore`
      Set the text extractor that can be used for extracting text from binary content.
      Specified by:
        `setTextExtractors` in interface `BinaryStore`
      Parameters:
        `textExtractors` - a non-null `TextExtractors` instance

    - #### setMimeTypeDetector

          public void setMimeTypeDetector(MimeTypeDetector mimeTypeDetector)

      Description copied from interface: `BinaryStore`
      Set the MIME type detector that can be used for determining the MIME type for binary content.
      Specified by:
        `setMimeTypeDetector` in interface `BinaryStore`
      Parameters:
        `mimeTypeDetector` - the detector

    - #### getText

          public final String getText(BinaryValue binary)
                               throws BinaryStoreException

      Description copied from interface: `BinaryStore`
      Get the text that can be extracted from this binary content. If text extraction isn't enabled (either full text search is not enabled or there aren't any configured extractors), this returns `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

      In general, the implementation from `AbstractBinaryStore` should be enough and any custom `BinaryStore` implementations aren't expected to implement this.
      Specified by:
        `getText` in interface `BinaryStore`
      Parameters:
        `binary` - the binary content; may not be null
      Returns:
        the extracted text, or null if none could be extracted
      Throws:
        `BinaryStoreException` - if the binary content could not be accessed or if the given binary value cannot be found within the store.

    - #### getMimeType

          public String getMimeType(BinaryValue binary,
                           String name)
                             throws IOException,
                                    RepositoryException

      Description copied from interface: `BinaryStore`
      Get the MIME type for this binary value, never `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.

      Specified by:
        `getMimeType` in interface `BinaryStore`
      Parameters:
        `binary` - the binary content; may not be null
        `name` - the name of the content, useful for determining the MIME type; may be null if not known
      Returns:
        the MIME type of the content, as determined by the installed detectors or `null` if none of the detectors can determine it.
      Throws:
        `IOException` - if there is a problem reading the binary content
        `BinaryStoreException` - if the binary value cannot be found in the store
        `RepositoryException` - if any other error occurs.

    - #### hasBinary

          public boolean hasBinary(BinaryKey key)

      Description copied from interface: `BinaryStore`
      Searches for a binary which has the given key in this store.
      Specified by:
        `hasBinary` in interface `BinaryStore`
      Parameters:
        `key` - a non-null `BinaryKey` instance
      Returns:
        `true` if a binary with this key exists in this store, `false` otherwise.

    - #### getStoredMimeType

          protected abstract String getStoredMimeType(BinaryValue binaryValue)
                                               throws BinaryStoreException

      Returns the stored mime-type of a binary value.
      Parameters:
        `binaryValue` - a `non-null` `BinaryValue`
      Returns:
        either a non-empty `String` if a stored mimetype exists, or `null` if such a value doesn't exist yet.
      Throws:
        `BinaryStoreException` - if there's a problem accessing the binary store or if the binary value cannot be found in the store

    - #### storeMimeType

          protected abstract void storeMimeType(BinaryValue binaryValue,
                           String mimeType)
                                         throws BinaryStoreException

      Stores the given mime-type for a binary value.
      Parameters:
        `binaryValue` - a `non-null` `BinaryValue`
        `mimeType` - a non-empty `String`
      Throws:
        `BinaryStoreException` - if there's a problem accessing the binary store

    - #### storeExtractedText

          public abstract void storeExtractedText(BinaryValue source,
                                String extractedText)
                                           throws BinaryStoreException

      Stores the extracted text of a binary value into this store.
      Parameters:
        `source` - a `non-null` `BinaryValue` instance from which the text was extracted
        `extractedText` - a `non-null` and `non-blank` string representing the extracted text
      Throws:
        `BinaryStoreException` - if the operation fails or if the extracted text cannot be stored for the given binary value (regardless of the reason)

    - #### getExtractedText

          public abstract String getExtractedText(BinaryValue source)
                                           throws BinaryStoreException

      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)
      Parameters:
        `source` - a `non-null` `BinaryValue` instance from which the text was extracted
      Returns:
        a `String` representing the extracted text, or `null` if such text hasn't been stored in this store previously.
      Throws:
        `BinaryStoreException` - if the binary value cannot be found in the store.

    - #### extractors

          protected final TextExtractors extractors()

      Get the text extractor that can be used to extract text by this store.
      Returns:
        the text extractor; never null

    - #### detector

          protected final MimeTypeDetector detector()

      Get the MIME type detector that can be used to find the MIME type for binary content
      Returns:
        the detector; never null

    - #### storeValue

          public BinaryValue storeValue(InputStream stream,
                               String hint)
                                 throws BinaryStoreException

      Description copied from interface: `BinaryStore`
      Store the binary value and return the JCR representation. Note that if the binary content in the supplied stream is already persisted in the store, the store may simply return the binary value referencing the existing content.
      Specified by:
        `storeValue` in interface `BinaryStore`
      Parameters:
        `stream` - the stream containing the binary content to be stored; may not be null
        `hint` - a hint that the BinaryStore may use to make storage decisions about this input stream
      Returns:
        the binary value representing the stored binary value; never null
      Throws:
        `BinaryStoreException` - if there any unexpected problem

    - #### start

          public void start()

      Description copied from interface: `BinaryStore`
      Initialize the store and get ready for use.
      Specified by:
        `start` in interface `BinaryStore`

    - #### shutdown

          public void shutdown()

      Description copied from interface: `BinaryStore`
      Shuts down the store.
      Specified by:
        `shutdown` in interface `BinaryStore`

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.