Class BinaryType

  • All Implemented Interfaces:
    Binary, Streamable
    Direct Known Subclasses:
    CryptoBinary

    public class BinaryType
    extends Object
    implements Binary
    Datatype for binary data or BLOB (binary large object).
    Since:
    1.0.0
    • Field Detail

      • data

        protected final byte[] data
        See Also:
        getData()
    • Constructor Detail

      • BinaryType

        public BinaryType​(byte[] data)
        The constructor.
        Parameters:
        data - the raw binary data.
      • BinaryType

        public BinaryType​(String base64)
        The constructor (mainly for testing).
        Parameters:
        base64 - the data as base64.
    • Method Detail

      • getMinLength

        protected int getMinLength()
        Returns:
        the minimum allowed length of the data. Implementation has to be static and return the same value for each class with each call.
      • getMaxLength

        protected int getMaxLength()
        Returns:
        the maximum allowed length of the data. Implementation has to be static and return the same value for each class with each call.
      • getDataByte

        public byte getDataByte​(int index)
        Specified by:
        getDataByte in interface Binary
        Parameters:
        index - the index of the requested byte starting from 1.
        Returns:
        the requested byte. If the given index exceeds the data (is greater or equal to length) 0 is returned.
      • getData

        public byte[] getData()
        Description copied from interface: Binary
        ATTENTION:
        Sub-types often represent sensible data. Be careful to pass these data in raw form (unencrypted).
        Specified by:
        getData in interface Binary
        Returns:
        the raw encoded data. Array will be copied to prevent manipulation. Hence, this method is expensive and subsequent calls shall be avoided.
      • getData

        public void getData​(byte[] buffer,
                            int offset)
        Description copied from interface: Binary
        Copies the data into the given buffer.
        Specified by:
        getData in interface Binary
        Parameters:
        buffer - the byte array to copy the data to. Has to have enough capacity left for the length of this BLOB.
        offset - the index where to start copying to buffer.
      • getLength

        public int getLength()
        Specified by:
        getLength in interface Binary
        Returns:
        the length of this BLOB in bytes (array length of getData()).
      • isZeros

        public boolean isZeros()
        Specified by:
        isZeros in interface Binary
        Returns:
        true if the data contains only zeros (0 values), false otherwise.
      • hashCode

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

        public static String formatHex​(byte[] data)
        Parameters:
        data - the data to format.
        Returns:
        the given data formatted as hex String.
      • parseBase64

        public static byte[] parseBase64​(String base64)
        Parameters:
        base64 - the BLOB to parse as Base64 encoded String.
        Returns:
        the parsed base64 String.
      • toBytes

        public static byte[] toBytes​(long value)
        Parameters:
        value - the long value.
        Returns:
        the value as array of 8 bytes.
      • toBytes

        public static byte[] toBytes​(int value)
        Parameters:
        value - the int value.
        Returns:
        the value as array of 4 bytes.
      • toLong

        public static long toLong​(byte[] data)
        Parameters:
        data - the long value as byte[] with a maximum length of 8 (see toBytes(long)).
        Returns:
        the value long.
      • toInt

        public static long toInt​(byte[] data)
        Parameters:
        data - the long value as byte[] with a maximum length of 8 (see toBytes(long)).
        Returns:
        the value long.