public class DefaultByteSource extends Object implements 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.CreatorInitializercreator| Constructor and Description |
|---|
DefaultByteSource(byte[] bytes) |
DefaultByteSource(char[] chars)
Creates an instance by converting the characters to a byte array (assumes UTF-8 encoding).
|
DefaultByteSource(File file)
Creates an instance by converting the file to a byte array.
|
DefaultByteSource(InputStream stream)
Creates an instance by converting the stream to a byte array.
|
DefaultByteSource(String 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 o) |
byte[] |
getBytes()
Returns the wrapped byte array.
|
int |
hashCode() |
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 DefaultByteSource(byte[] bytes)
public DefaultByteSource(char[] chars)
chars - the source characters to use to create the underlying byte array.public DefaultByteSource(String string)
string - the source string to convert to a byte array (assumes UTF-8 encoding).public DefaultByteSource(File file)
file - the file from which to acquire bytes.public DefaultByteSource(InputStream stream)
stream - the stream from which to acquire bytes.public byte[] getBytes()
ByteSourcegetBytes in interface ByteSourcepublic boolean isEmpty()
ByteSourcetrue if the underlying wrapped byte array is null or empty (zero length), false
otherwise.isEmpty in interface ByteSourcetrue if the underlying wrapped byte array is null or empty (zero length), false
otherwise.public String toHex()
ByteSourcetoHex in interface ByteSourcepublic String toBase64()
ByteSourcetoBase64 in interface ByteSourceCopyright © 2014–2018. All rights reserved.