public final class BinaryValue extends Object
In almost all cases Riak is character asSet agnostic when it comes to data; buckets, keys, values and metadata are all stored in Riak simply as bytes.
This utility class is used throughout the client in order to encapsulate
and allow access to those bytes by the user when the data is generally
representative of a String
so that any character asSet may be used.
If you are using this class directly keep in mind that any modification to the
wrapped byte[] post creation via either a retained reference to the
array after calling unsafeCreate() or accessing the array directly via
unsafeGetValue() will lead to undefined behavior in regard to thread
safety and visibility.
|
Modifier and Type | Method and Description |
---|---|
static BinaryValue |
create(byte[] data)
Create a BinaryValue containing a copy of the supplied
byte[] |
static BinaryValue |
create(String data)
Create a BinaryValue containing a copy of the supplied String
encoded using the default character asSet.
|
static BinaryValue |
create(String data,
Charset charset)
Create a BinaryValue containing a copy of the supplied string
encoded using the supplied Charset.
|
static BinaryValue |
createFromUtf8(String data)
Create a BinaryValue containing a copy of the supplied String
encoded using UTF-8.
|
boolean |
equals(Object other) |
byte[] |
getValue()
Return a copy of the wrapped
byte[] |
int |
hashCode() |
int |
length()
Return the length of the wrapped
byte[] |
String |
toString()
Return the wrapped
byte[] as a String. |
String |
toString(Charset charset)
Return the wrapped
byte[] as a String |
String |
toStringUtf8()
Return the wrapped
byte[] as a String. |
static BinaryValue |
unsafeCreate(byte[] data)
Create a BinaryValue containing the supplied
byte[] |
byte[] |
unsafeGetValue()
Return the wrapped
byte[] |
public static BinaryValue create(byte[] data)
byte[]
A copy of the supplied byte[]
is made.
data
- the byte[]
to copyBinaryValue
public static BinaryValue create(String data)
data
- the data to copyBinaryValue
public static BinaryValue createFromUtf8(String data)
data
- the data to copyBinaryValue
public static BinaryValue create(String data, Charset charset)
data
- the data to copycharset
- the charset to use for encodingBinaryValue
public static BinaryValue unsafeCreate(byte[] data)
byte[]
The byte[]
is not copied.
data
- the byte[]
to wrapBinaryValue
The supplied byte[] is not copied and the reference is used
directly. Retaining a reference to this array and making subsequent
changes will lead to undefined behavior in regard to thread safety and
visibility. |
public byte[] getValue()
byte[]
Arrays.copyOf(byte[], int)
is used to copy the internal byte[]
byte[]
public byte[] unsafeGetValue()
byte[]
byte[]
This method exposes the internal byte[] directly.
Modifying the contents of this array will lead to undefined behavior in
regard to thread safety and visibility. |
public String toString()
byte[]
as a String.
The default character asSet is used for encoding.
public String toStringUtf8()
byte[]
as a String.
UTF-8 is used for encoding.
String
created using the UTF-8 Charset
public String toString(Charset charset)
byte[]
as a String
The supplied Charset
is used to convert the bytes.
String
created using the supplied Charset
public int length()
byte[]
Copyright © 2014. All rights reserved.