Package oracle.nosql.driver.values
Class BinaryValue
- java.lang.Object
-
- oracle.nosql.driver.values.FieldValue
-
- oracle.nosql.driver.values.BinaryValue
-
- All Implemented Interfaces:
Comparable<FieldValue>
public class BinaryValue extends FieldValue
AFieldValue
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 usingencodeBase64(byte[])
.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class oracle.nosql.driver.values.FieldValue
FieldValue.Type
-
-
Constructor Summary
Constructors Constructor Description BinaryValue(byte[] value)
Creates a new instance.BinaryValue(String value)
Creates a new instance from a Base64 encoded string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(FieldValue other)
Returns 0 if the two values are equal in terms of length and byte content, otherwise it returns -1.static byte[]
decodeBase64(String binString)
Decode the specified Base64 string into a byte array.static String
encodeBase64(byte[] buffer)
Encode the specified byte array into a Base64 encoded string.boolean
equals(Object other)
FieldValue.Type
getType()
Returns the type of the objectbyte[]
getValue()
Returns the binary value of this objectint
hashCode()
String
toJson(JsonOptions options)
Returns a quoted string of the value as Base64.-
Methods inherited from class oracle.nosql.driver.values.FieldValue
asArray, asBinary, asBoolean, asDouble, asInteger, asJsonNull, asLong, asMap, asNull, asNumber, asString, asTimestamp, castAsDouble, createFromJson, createFromJson, createFromJson, getBinary, getBoolean, getDouble, getInt, getLong, getNumber, getSerializedSize, getString, getTimestamp, isAnyNull, isArray, isAtomic, isBinary, isBoolean, isDouble, isInteger, isJsonNull, isLong, isMap, isNull, isNumber, isNumeric, isString, isTimestamp, toJson, toString
-
-
-
-
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
-
getType
public FieldValue.Type getType()
Description copied from class:FieldValue
Returns the type of the object- Specified by:
getType
in classFieldValue
- Returns:
- the type
-
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 classFieldValue
- 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[])
.
-
encodeBase64
public static String encodeBase64(byte[] buffer)
Encode the specified byte array into a Base64 encoded string. This string can be decoded usingdecodeBase64(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 usingencodeBase64(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.
-
-