public class SimpleByteSource 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:
ByteSource
File
InputStream
ByteSource.Util
Constructor and Description |
---|
SimpleByteSource(byte[] bytes) |
SimpleByteSource(ByteSource source)
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 file)
Creates an instance by converting the file to a byte array.
|
SimpleByteSource(InputStream stream)
Creates an instance by converting the stream to a byte array.
|
SimpleByteSource(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() |
static boolean |
isCompatible(Object o)
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(String string)
string
- the source string to convert to a byte array (assumes UTF-8 encoding).public SimpleByteSource(ByteSource source)
source
- the source to use to populate the underlying byte array.public SimpleByteSource(File file)
file
- the file from which to acquire bytes.public SimpleByteSource(InputStream stream)
stream
- the stream from which to acquire bytes.public static boolean isCompatible(Object o)
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[]
ByteSource
String
File
InputStream
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 String toHex()
ByteSource
toHex
in interface ByteSource
public String toBase64()
ByteSource
toBase64
in interface ByteSource
Copyright © 2004–2018 The Apache Software Foundation. All rights reserved.