org.modeshape.jcr.value.binary

## Class CompositeBinaryStore

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

- All Implemented Interfaces:
    BinaryStore

      public class CompositeBinaryStore
      extends Object
      implements BinaryStore

  A `BinaryStore` implementation that stores files in other BinaryStores. This store is initialized with a map of number of BinaryStores. On retrieval, the CompositeBinaryStore will look in all the other BinaryStores for the value. When storing a value, the CompositeBinaryStore may receive a StorageHint that MAY be used when determining which named BinaryStore to write to. If a storage hint is not provided (or doesn't match a store), the value will be stored in the default store.

- - ### Field Summary

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

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CompositeBinaryStore(Map<String,BinaryStore> namedStores)` Initialize a new CompositeBinaryStore using a Map of other BinaryKeys that are keyed by an implementer-provided key.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `BinaryStore` | `findBinaryStoreContainingKey(BinaryKey key)` Get the named binary store that contains the key
    `Iterable<BinaryKey>` | `getAllBinaryKeys()` Obtain an iterable implementation containing all of the store's binary keys of those binaries that are in use.
    `InputStream` | `getInputStream(BinaryKey key)` Get an `InputStream` to the binary content with the supplied key.
    `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.
    `Iterator<Map.Entry<String,BinaryStore>>` | `getNamedStoreIterator()` Get an iterator over all the named stores
    `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` | `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.
    `void` | `moveValue(BinaryKey key, String destination)` Move a BinaryKey to a named store
    `BinaryKey` | `moveValue(BinaryKey key, String source, String destination)` Move a value from one named store to another store
    `void` | `removeValuesUnusedLongerThan(long minimumAge, TimeUnit unit)` Remove binary values that have been `unused` for at least the specified amount of time.
    `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()` Shut down all the named stores
    `void` | `start()` Initialize the store, and initialize all the named stores.
    `BinaryValue` | `storeValue(InputStream stream, boolean markAsUnused)` Store the binary value and return the JCR representation.
    `BinaryValue` | `storeValue(InputStream stream, String hint, boolean markAsUnused)` 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`

- - ### Field Detail

    - #### logger

          protected Logger logger

  - ### Constructor Detail

    - #### CompositeBinaryStore

          public CompositeBinaryStore(Map<String,BinaryStore> namedStores)

      Initialize a new CompositeBinaryStore using a Map of other BinaryKeys that are keyed by an implementer-provided key. The named stores must include a default BinaryStore that will be used in the absence of storage hints.
      Parameters:
        `namedStores` - a `Map` of inner stores, grouped by the hint.

  - ### Method Detail

    - #### start

          public void start()

      Initialize the store, and initialize all the named stores.
      Specified by:
        `start` in interface `BinaryStore`

    - #### shutdown

          public void shutdown()

      Shut down all the named stores
      Specified by:
        `shutdown` in interface `BinaryStore`

    - #### 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

    - #### storeValue

          public BinaryValue storeValue(InputStream stream,
                               boolean markAsUnused)
                                 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
        `markAsUnused` - 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.
      Returns:
        the binary value representing the stored binary value; never null
      Throws:
        `BinaryStoreException` - if there any unexpected problem

    - #### storeValue

          public BinaryValue storeValue(InputStream stream,
                               String hint,
                               boolean markAsUnused)
                                 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
        `markAsUnused` - 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.
      Returns:
        the binary value representing the stored binary value; never null
      Throws:
        `BinaryStoreException` - if there any unexpected problem

    - #### moveValue

          public BinaryKey moveValue(BinaryKey key,
                            String source,
                            String destination)
                              throws BinaryStoreException

      Move a value from one named store to another store
      Parameters:
        `key` - Binary key to transfer from the source store to the destination store
        `source` - a hint for discovering the source repository; may be null
        `destination` - a hint for discovering the destination repository
      Returns:
        the `BinaryKey` value of the moved binary, never `null`
      Throws:
        `BinaryStoreException` - if a source store cannot be found or the source store does not contain the binary key

    - #### moveValue

          public void moveValue(BinaryKey key,
                       String destination)
                         throws BinaryStoreException

      Move a BinaryKey to a named store
      Parameters:
        `key` - Binary key to transfer from the source store to the destination store
        `destination` - a hint for discovering the destination repository
      Throws:
        `BinaryStoreException` - if anything unexpected fails

    - #### getInputStream

          public InputStream getInputStream(BinaryKey key)
                                     throws BinaryStoreException

      Description copied from interface: `BinaryStore`
      Get an `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.
      Specified by:
        `getInputStream` in interface `BinaryStore`
      Parameters:
        `key` - the key to the binary content; never null
      Returns:
        the input stream through which the content can be read, `never null`
      Throws:
        `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.

    - #### hasBinary

          public boolean hasBinary(BinaryKey key)

      Description copied from interface: `BinaryStore`
      Searches for a binary which has the given key in this store. The store should return `true` as long the binary is still present physically, regardless of any "trash" semantics.
      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.

    - #### markAsUnused

          public void markAsUnused(Iterable<BinaryKey> keys)
                            throws BinaryStoreException

      Description copied from interface: `BinaryStore`
      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. This method ignores any keys for values not stored within this store.
      Specified by:
        `markAsUnused` in interface `BinaryStore`
      Parameters:
        `keys` - the keys for the binary values that are no longer needed
      Throws:
        `BinaryStoreException` - if there is a problem marking any of the supplied binary values as unused

    - #### markAsUsed

          public void markAsUsed(Iterable<BinaryKey> keys)
                          throws BinaryStoreException

      Description copied from interface: `BinaryStore`
      Marks the binary with supplied keys as used. This method should ignore any keys which are not present in the store.
      Specified by:
        `markAsUsed` in interface `BinaryStore`
      Parameters:
        `keys` - a `BinaryKey` `Iterable`, may not be null
      Throws:
        `BinaryStoreException` - if anything unexpected fails.

    - #### removeValuesUnusedLongerThan

          public void removeValuesUnusedLongerThan(long minimumAge,
                                          TimeUnit unit)
                                            throws BinaryStoreException

      Description copied from interface: `BinaryStore`
      Remove binary values that have been `unused` for at least the specified amount of time.
      Specified by:
        `removeValuesUnusedLongerThan` in interface `BinaryStore`
      Parameters:
        `minimumAge` - the minimum time that a binary value has been `unused` before it can be removed; must be non-negative
        `unit` - the time unit for the minimum age; may not be null
      Throws:
        `BinaryStoreException` - if there is a problem removing the unused values

    - #### getText

          public 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.

    - #### getAllBinaryKeys

          public Iterable<BinaryKey> getAllBinaryKeys()
                                               throws BinaryStoreException

      Description copied from interface: `BinaryStore`
      Obtain an iterable implementation containing all of the store's binary keys of those binaries that are in use. The resulting iterator may be lazy, in the sense that it may determine additional `BinaryKey`s only as the iterator is used.
      Specified by:
        `getAllBinaryKeys` in interface `BinaryStore`
      Returns:
        the iterable set of binary keys; never null
      Throws:
        `BinaryStoreException` - if anything unexpected happens.

    - #### getNamedStoreIterator

          public Iterator<Map.Entry<String,BinaryStore>> getNamedStoreIterator()

      Get an iterator over all the named stores
      Returns:
        an iterator over the map of binary stores and their given names

    - #### findBinaryStoreContainingKey

          public BinaryStore findBinaryStoreContainingKey(BinaryKey key)

      Get the named binary store that contains the key
      Parameters:
        `key` - the key to the binary content; never null
      Returns:
        the BinaryStore that contains the given key

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