public class Binary extends Object implements Comparable<Binary>, Stringable, Serializable
Constructor and Description |
---|
Binary(byte[] bytes)
Create a binary instance that wraps a created byte array.
|
Modifier and Type | Method and Description |
---|---|
String |
asString()
Make a string representation of the instance value.
|
int |
compareTo(Binary other) |
static Binary |
copy(byte[] bytes)
Convenience method to copy a byte array into a byte sequence.
|
static Binary |
copy(byte[] bytes,
int off,
int len)
Convenience method to copy a part of a byte array into a byte sequence.
|
static Binary |
empty()
Method to create a Binary with 0 bytes.
|
boolean |
equals(Object o) |
static Binary |
fromBase64(String base64)
Decode base64 string and wrap the result in a byte sequence.
|
static Binary |
fromHexString(String hex)
Parse a hex string as bytes.
|
byte[] |
get()
Get a copy of the backing array.
|
int |
get(byte[] into)
Get a copy of the backing array.
|
ByteBuffer |
getByteBuffer()
Get a byte buffer wrapping the binary data.
|
InputStream |
getInputStream()
Get an input stream that reads from the stored bytes.
|
int |
hashCode() |
int |
length()
Get the length of the backing array.
|
static Binary |
read(InputStream in,
int len)
Read a binary buffer from input stream.
|
String |
toBase64()
Get the sequence encoded as base64.
|
String |
toHexString()
Make a hex string from a byte array.
|
String |
toString() |
static Binary |
wrap(byte[] bytes)
Convenience method to wrap a byte array into a byte sequence.
|
int |
write(OutputStream out)
Write bytes to output stream.
|
public Binary(byte[] bytes)
bytes
- The byte array to wrap.public static Binary wrap(byte[] bytes)
bytes
- Bytes to wrap.public static Binary copy(byte[] bytes)
bytes
- Bytes to wrap.public static Binary copy(byte[] bytes, int off, int len)
bytes
- Bytes to wrap.off
- Offset in source bytes to start reading from.len
- Number of bytes to copy.public static Binary empty()
public int length()
public byte[] get()
public int get(byte[] into)
into
- Target ro copy into.public static Binary fromBase64(String base64)
base64
- The string to decode.public String toBase64()
public static Binary fromHexString(String hex)
hex
- The hex string.public String toHexString()
public ByteBuffer getByteBuffer()
public InputStream getInputStream()
public static Binary read(InputStream in, int len) throws IOException
in
- Input stream to read.len
- Number of bytes to read.IOException
- If unable to read completely what's expected.public int write(OutputStream out) throws IOException
out
- Stream to write to.IOException
- When unable to write to stream.public int compareTo(Binary other)
compareTo
in interface Comparable<Binary>
public String asString()
Stringable
asString
in interface Stringable
Copyright © 2017. All rights reserved.