public class SimpleByteSource extends Objectimplements ByteSource
ByteSource implementation that maintains an internal
byte[] array and uses the
Hex and
Base64 codec classes to support the
toHex() and
toBase64() implementations.
The constructors on this class accept the following implicit byte-backed data types and will convert them to a byte-array automatically:
ByteSourceFileInputStreamByteSource.Util | Constructor and Description |
|---|
SimpleByteSource(byte[] bytes)
|
SimpleByteSource(ByteSource
Creates an instance using the sources bytes directly - it does not create a copy of the argument's byte array.
|
SimpleByteSource(char[] chars)
Creates an instance by converting the characters to a byte array (assumes UTF-8 encoding).
|
SimpleByteSource(File
Creates an instance by converting the file to a byte array.
|
SimpleByteSource(InputStream
Creates an instance by converting the stream to a byte array.
|
SimpleByteSource(String
Creates an instance by converting the String to a byte array (assumes UTF-8 encoding).
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object
|
byte[] |
getBytes()
Returns the wrapped byte array.
|
int |
hashCode()
|
static boolean |
isCompatible(Object
Returns
true if the specified object is a recognized data type that can be easily converted to bytes by instances of this class,
false otherwise.
|
boolean |
isEmpty()
Returns
true if the underlying wrapped byte array is null or empty (zero length),
false otherwise.
|
String |
toBase64()
Returns the
Base 64-formatted String representation of the underlying wrapped byte array.
|
String |
toHex()
Returns the
Hex-formatted String representation of the underlying wrapped byte array.
|
String |
toString()
|
public SimpleByteSource(byte[] bytes)
public SimpleByteSource(char[] chars)
chars - the source characters to use to create the underlying byte array.
public SimpleByteSource(Stringstring)
string - the source string to convert to a byte array (assumes UTF-8 encoding).
public SimpleByteSource(ByteSourcesource)
source - the source to use to populate the underlying byte array.
public SimpleByteSource(Filefile)
file - the file from which to acquire bytes.
public SimpleByteSource(InputStreamstream)
stream - the stream from which to acquire bytes.
public static boolean isCompatible(Objecto)
true if the specified object is a recognized data type that can be easily converted to bytes by instances of this class,
false otherwise.
This implementation returns
true IFF the specified object is an instance of one of the following types:
byte[]char[]ByteSourceStringFileInputStream
o - the object to test to see if it can be easily converted to bytes by instances of this class.
true if the specified object can be easily converted to bytes by instances of this class,
false otherwise.
public byte[] getBytes()
ByteSource
getBytes in interface
ByteSource
public boolean isEmpty()
ByteSource
true if the underlying wrapped byte array is null or empty (zero length),
false otherwise.
isEmpty in interface
ByteSource
true if the underlying wrapped byte array is null or empty (zero length),
false otherwise.
public StringtoHex()
ByteSource
toHex in interface
ByteSource
public StringtoBase64()
ByteSource
toBase64 in interface
ByteSource
public StringtoString()
public int hashCode()
public boolean equals(Objecto)