Class BinaryValue

  • All Implemented Interfaces:
    Comparable<FieldValue>

    public class BinaryValue
    extends FieldValue
    A FieldValue instance representing a binary value. Instances of BinaryValue are only created by construction or returned by data operations. They will never be directly created by parsing JSON. On input a Base64 encoded string can be accepted as a binary type if the database type is binary for the field. When represented as JSON this object is encoded as Base64 using encodeBase64(byte[]).
    • Constructor Detail

      • BinaryValue

        public BinaryValue​(byte[] value)
        Creates a new instance.
        Parameters:
        value - the value to use
      • BinaryValue

        public BinaryValue​(String value)
        Creates a new instance from a Base64 encoded string.
        Parameters:
        value - the value to use
        Throws:
        IllegalArgumentException - if the value is not a valid Base64 encoded value.
    • Method Detail

      • getValue

        public byte[] getValue()
        Returns the binary value of this object
        Returns:
        the binary value
      • compareTo

        public int compareTo​(FieldValue other)
        Returns 0 if the two values are equal in terms of length and byte content, otherwise it returns -1.
      • toJson

        public String toJson​(JsonOptions options)
        Returns a quoted string of the value as Base64.
        Overrides:
        toJson in class FieldValue
        Parameters:
        options - configurable options used to affect the JSON output format of some data types. May be null.
        Returns:
        a quoted, Base64-encoded string encoded using encodeBase64(byte[]).
      • hashCode

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

        public static String encodeBase64​(byte[] buffer)
        Encode the specified byte array into a Base64 encoded string. This string can be decoded using decodeBase64(java.lang.String).
        Parameters:
        buffer - the input buffer
        Returns:
        the encoded string
      • decodeBase64

        public static byte[] decodeBase64​(String binString)
        Decode the specified Base64 string into a byte array. The string must have been encoded using encodeBase64(byte[]) or the same algorithm.
        Parameters:
        binString - the encoded input string
        Returns:
        the decoded array
        Throws:
        IllegalArgumentException - if the value is not a valid Base64 encoded value.