Class Binary<T extends Serializable>

  • 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:
    Serialized Form
    • Constructor Detail

      • Binary

        public Binary​(T object)
               throws IOException
        Creates a Binary from a Serializable.
        Parameters:
        object - the Serializable to be stored in the database
        Throws:
        IOException - if some serialization error.
      • Binary

        public Binary()
        Creates an empty binary.
    • Method Detail

      • freeze

        public void freeze()
        Description copied from interface: Freezable
        Makes this object immutable.
        Specified by:
        freeze in interface Freezable
      • clone

        public Binary<T> clone()

        Cloned binaries are always not frozen.

        Overrides:
        clone in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • createBinary

        public static <T extends SerializableBinary<T> createBinary​(InputStream stream,
                                                                      int bufSize,
                                                                      boolean frozen)
                                                               throws IOException
        Creates a Binary out of an InputStream. Used to read a Binary from 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 null
        bufSize - 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 this 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)
        Returns:
        the length of the Binary in bytes
      • getInputStream

        public InputStream getInputStream()
        Gets the stream to store the Binary in the database.
        Returns:
        the stream associated to the database.
      • setObject

        public void setObject​(T object)
                       throws IOException
        Sets the serializable.
        Parameters:
        object - the serializable object.
        Throws:
        IOException - if object could not be serialized