Holger's Java API

## com.antelmann.io
Class BinaryData

    java.lang.Object
      com.antelmann.io.BinaryData

All Implemented Interfaces:
  ValueRetriever<InputStream>, ValueSetter<ValueRetriever<InputStream>>, Wrapped<ValueRetriever<InputStream>>, Serializable

    public class BinaryData

extends Object
implements ValueRetriever<InputStream>, ValueSetter<ValueRetriever<InputStream>>, Wrapped<ValueRetriever<InputStream>>, Serializable

allows to keep an instance that will produce an InputStream on demand while supporting serialization of the same. If a URL is set as the source, only the URL is serialized; if an `SQLValueRetriever` is used, only the same is serialized; in any other case, a byte array is generated and serialized.

Since:
  7/30/2013
Author:
  Holger Antelmann
See Also:
  `Placeholder`, `ImageHolder`, Serialized Form

Constructor Summary
`BinaryData()`
`BinaryData(byte[] array)`
`BinaryData(Connection con, String table, String keyColumn, Object keyValue, String dataColumn, DBTransaction tx)`
`BinaryData(Connection con, String table, String keyColumn, String keyValue, String dataColumn)`
`BinaryData(DBClassStore<?> store, Object keyValue, String dataColumn)`
`BinaryData(File file)` serialized versions will store the entire stream and not a reference to the file.
`BinaryData(InputStream in)`
`BinaryData(SQLValueRetriever sr)`
`BinaryData(URL url)`
`BinaryData(ValueRetriever<Connection> conRetriever, String table, String keyColumn, Object keyValue, String dataColumn, DBTransaction tx)`
`BinaryData(ValueRetriever<InputStream> retriever)`

Method Summary
`void` `addPropertyChangeListener(PropertyChangeListener listener)`
`void` `addVetoableChangeListener(VetoableChangeListener listener)`
`BinaryData` `cacheInFile(File file, boolean serializeAsURL)` note that the caller has to take care that the given file is later deleted when it's not used anymore
`BinaryData` `convertToByteArray()` replaces the existing retriever with one that holds the relevant data in-memory as byte array.
`static ValueRetriever<InputStream>` `createRetriever(ValueRetriever<Connection> conRetriever, String table, String keyColumn, Object keyValue, String dataColumn, DBTransaction tx)` allows to easily retrieve binary data from a specific database entry
`InputStream` `getInputStream()` same as getRelevantValue()
`URL` `getInternalURL()`
`PropertyChangeListener[]` `getPropertyChangeListeners()`
`Reader` `getReader()`
`Reader` `getReader(String charset)`
`InputStream` `getRelevantValue()` returns the relevant value for this instance at the time of calling
`VetoableChangeListener[]` `getVetoableChangeListeners()`
`boolean` `isBasedOnURL()`
`void` `removePropertyChangeListener(PropertyChangeListener listener)`
`void` `removeVetoableChangeListener(VetoableChangeListener listener)`
`void` `setData(byte[] array)`
`void` `setDatabaseValue(SQLValueRetriever dbdata)` on serialization, only the given parameter is serialized
`void` `setRelevantValue(ValueRetriever<InputStream> retriever)` sets the relevant value for this instance with the given value
`void` `setRetriever(ValueRetriever<InputStream> retriever)`
`void` `setURL(URL url)` on serialization, only the URL is serialized
`void` `setValue(InputStream in)` requires that the entire stream fits into memory
`void` `storeTo(File file)`
`byte[]` `toByteArray()`
`ValueRetriever<InputStream>` `unwrap()` returns the embedded instance that this wrapper encloses

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### BinaryData

    public BinaryData()

### BinaryData

    public BinaryData(byte[] array)

### BinaryData

    public BinaryData(InputStream in)

### BinaryData

    public BinaryData(URL url)

### BinaryData

    public BinaryData(SQLValueRetriever sr)

### BinaryData

    public BinaryData(File file)

  serialized versions will store the entire stream and not a reference to the file. If you don't want this, use `BinaryData(URL)` instead.

### BinaryData

    public BinaryData(Connection con,
                      String table,
                      String keyColumn,
                      String keyValue,
                      String dataColumn)

See Also:
  `BinaryData(ValueRetriever, String, String, Object, String, DBTransaction)`

### BinaryData

    public BinaryData(Connection con,
                      String table,
                      String keyColumn,
                      Object keyValue,
                      String dataColumn,
                      DBTransaction tx)

See Also:
  `BinaryData(ValueRetriever, String, String, Object, String, DBTransaction)`

### BinaryData

    public BinaryData(ValueRetriever<Connection> conRetriever,
                      String table,
                      String keyColumn,
                      Object keyValue,
                      String dataColumn,
                      DBTransaction tx)

See Also:
  `createRetriever(ValueRetriever, String, String, Object, String, DBTransaction)`

### BinaryData

    public BinaryData(DBClassStore<?> store,
                      Object keyValue,
                      String dataColumn)

### BinaryData

    public BinaryData(ValueRetriever<InputStream> retriever)

Method Detail

### createRetriever

    public static ValueRetriever<InputStream> createRetriever(ValueRetriever<Connection> conRetriever,
                                                              String table,
                                                              String keyColumn,
                                                              Object keyValue,
                                                              String dataColumn,
                                                              DBTransaction tx)

  allows to easily retrieve binary data from a specific database entry

  Parameters:
    `conRetriever` - the retriever for the database connection
    `table` - the table from which the data is to be retrieved
    `keyColumn` - specifies the column that identifies the row that is to be selected
    `keyValue` - the value of the id column that specifies the row to be selected
    `dataColumn` - the column that contains the binary data
    `tx` - if non-null, the data is retrieved within a transactional context

### convertToByteArray

    public BinaryData convertToByteArray()
                                  throws IOException,
                                         OutOfMemoryError

  replaces the existing retriever with one that holds the relevant data in-memory as byte array. Note that this may quickly throw an `OutOfMemoryError` if the data is too big

  Throws:
    `IOException`
    `OutOfMemoryError`

### toByteArray

    public byte[] toByteArray()
                       throws IOException

  Throws:
    `IOException`

### cacheInFile

    public BinaryData cacheInFile(File file,
                                  boolean serializeAsURL)
                           throws IOException

  note that the caller has to take care that the given file is later deleted when it's not used anymore

  Throws:
    `IOException`

### storeTo

    public void storeTo(File file)
                 throws IOException

  Throws:
    `IOException`

### setData

    public void setData(byte[] array)

### setDatabaseValue

    public void setDatabaseValue(SQLValueRetriever dbdata)

  on serialization, only the given parameter is serialized

### setURL

    public void setURL(URL url)

  on serialization, only the URL is serialized

### isBasedOnURL

    public boolean isBasedOnURL()

### getInternalURL

    public URL getInternalURL()
                       throws OptionNotAvailableWarning

  Throws:
    `OptionNotAvailableWarning`

### setRetriever

    public final void setRetriever(ValueRetriever<InputStream> retriever)
                            throws IllegalArgumentException

  Throws:
    `IllegalArgumentException` - if a `VetoableChangeListener` is throwing a `PropertyVetoException`

### setValue

    public void setValue(InputStream in)
                  throws IOException,
                         OutOfMemoryError

  requires that the entire stream fits into memory

  Throws:
    `IOException`
    `OutOfMemoryError`

### setRelevantValue

    public final void setRelevantValue(ValueRetriever<InputStream> retriever)

  Description copied from interface: `ValueSetter`
  sets the relevant value for this instance with the given value

  Specified by:
    `setRelevantValue` in interface `ValueSetter<ValueRetriever<InputStream>>`

### addPropertyChangeListener

    public void addPropertyChangeListener(PropertyChangeListener listener)

### removePropertyChangeListener

    public void removePropertyChangeListener(PropertyChangeListener listener)

### getPropertyChangeListeners

    public PropertyChangeListener[] getPropertyChangeListeners()

### addVetoableChangeListener

    public void addVetoableChangeListener(VetoableChangeListener listener)

### removeVetoableChangeListener

    public void removeVetoableChangeListener(VetoableChangeListener listener)

### getVetoableChangeListeners

    public VetoableChangeListener[] getVetoableChangeListeners()

### unwrap

    public ValueRetriever<InputStream> unwrap()

  Description copied from interface: `Wrapped`
  returns the embedded instance that this wrapper encloses

  Specified by:
    `unwrap` in interface `Wrapped<ValueRetriever<InputStream>>`

### getRelevantValue

    public final InputStream getRelevantValue()
                                       throws IOException

  Description copied from interface: `ValueRetriever`
  returns the relevant value for this instance at the time of calling

  Specified by:
    `getRelevantValue` in interface `ValueRetriever<InputStream>`
  Throws:
    `IOException` - if any resource to fulfill the request is not accessible

### getInputStream

    public InputStream getInputStream()
                               throws IOException

  same as getRelevantValue()

  Throws:
    `IOException`

### getReader

    public Reader getReader()
                     throws IOException

  Throws:
    `IOException`

### getReader

    public Reader getReader(String charset)
                     throws IOException

  Throws:
    `IOException`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads