T - the java class handled by this Binarypublic class Binary<T> extends Object implements Serializable, Cloneable
Its primary use is to store Serializables but it can handle arbitrary byte-data as well.
It uses the XXXBinaryStream-methods to read and write the data avoiding
the transactional limits of blobs, because blobs usually are only valid within a transaction.
Binary instead provides a blob-like interface while remaining valid outside transactions.
| Modifier and Type | Field and Description |
|---|---|
static int |
bufSize
initial default buffersize when reading from the database.
|
| Constructor and Description |
|---|
Binary()
Creates an empty binary
|
Binary(byte[] data)
Creates a Binary out of an array of arbitrary bytes.
|
Binary(T object)
Creates a Binary from a
Serializable. |
| Modifier and Type | Method and Description |
|---|---|
Binary<T> |
clone()
Clones the binary
|
static Binary<?> |
createBinary(InputStream stream,
int bufSize)
Creates a Binary out of an InputStream.
|
byte[] |
getData()
Retrieves the @{code Binary} data as a byte[]-array.
|
InputStream |
getInputStream()
Gets the stream to store the
Binary in the database. |
int |
getLength()
Gets the length in bytes of this
Binary. |
T |
getObject()
Retrieves the object encapsulated by the
Binary. |
void |
setData(byte[] data)
Sets the binary data.
|
public static int bufSize
public Binary(T object) throws IOException
Serializable.object - the Serializable to be stored in the databaseIOException - if some serialization error.public Binary(byte[] data)
data - the byte array to be stored in the database.public Binary()
public static Binary<?> createBinary(InputStream stream, int bufSize) throws IOException
Binary from the database.
Notice that stream.available() cannot be used according to sun's spec.
The stream is closed after creating the Binary.stream - the InputStream (associated to the database) to read from, may be nullbufSize - the initial buffer size, 0 = default size (bufSize)IOException - if reading from the input stream failedpublic int getLength()
Binary.
The length of a Binary is either the length of a byte-array (if Binary(byte[]) used)
or the length of the serialized object (if Binary(Object) used)Binary in bytespublic InputStream getInputStream()
Binary in the database.public T getObject() throws IOException, ClassNotFoundException
Binary.IOException - if reading the object failedClassNotFoundException - if class of a serialized object cannot be found.public byte[] getData()
public void setData(byte[] data)
data - the byte[]-array data.Tentackle - a domain driven enterprise framework