java.lang.Object
org.tentackle.common.Binary<T>
- Type Parameters:
T- the serializable type
- All Implemented Interfaces:
Serializable,Cloneable,Freezable
public class Binary<T extends Serializable>
extends Object
implements Serializable, Cloneable, Freezable
Datatype for storing arbitrary (binary) data in a database.
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.
Furthermore, binaries can be frozen, i.e. made immutable.
Keep in mind that the wrapped object is serialized when the Binary is created or setObject is invoked. Any subsequent changes to the object are not reflected in the internal byte array.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()static <T extends Serializable>
Binary<T> createBinary(InputStream stream, int bufSize, boolean frozen) Creates a Binary out of an InputStream.booleanvoidfreeze()Makes this object immutable.Gets the stream to store theBinaryin the database.intGets the length in bytes of thisBinary.Retrieves the object encapsulated by theBinary.inthashCode()voidSets the serializable.
-
Constructor Details
-
Binary
Creates a Binary from aSerializable.- Parameters:
object- theSerializableto be stored in the database- Throws:
IOException- if some serialization error.
-
Binary
public Binary()Creates an empty binary.
-
-
Method Details
-
freeze
public void freeze()Description copied from interface:FreezableMakes this object immutable. -
clone
Cloned binaries are always not frozen.
-
equals
-
hashCode
public int hashCode() -
createBinary
public static <T extends Serializable> Binary<T> createBinary(InputStream stream, int bufSize, boolean frozen) throws IOException Creates a Binary out of an InputStream. Used to read aBinaryfrom the database. Notice that stream.available() cannot be used according to sun's spec. The stream is closed after creating the Binary.- Type Parameters:
T- the serializable type- Parameters:
stream- the InputStream (associated to the database) to read from, may be nullbufSize- the initial buffer size, 0 = default size (bufSize)frozen- true if binary is frozen- Returns:
- the new Binary or null if stream is null or empty.
- Throws:
IOException- if reading from the input stream failed
-
getLength
public int getLength()Gets the length in bytes of thisBinary. The length of aBinaryis either the length of a byte-array (ifBinary(byte[])used) or the length of the serialized object (ifBinary(Object)used)- Returns:
- the length of the
Binaryin bytes
-
getInputStream
Gets the stream to store theBinaryin the database.- Returns:
- the stream associated to the database.
-
getObject
Retrieves the object encapsulated by theBinary.- Returns:
- the de-serialized object (retrieved from the db), or null if NULL-value
- Throws:
IOException- if reading the object failedClassNotFoundException- if class of a serialized object cannot be found.
-
setObject
Sets the serializable.- Parameters:
object- the serializable object.- Throws:
IOException- if object could not be serialized
-