public final class ArrayByteSource extends BeanByteSource implements org.joda.beans.ImmutableBean, Serializable
This implementation allows IOException to be avoided in many cases,
and to be able to create and retrieve the internal array unsafely.
| Modifier and Type | Field and Description |
|---|---|
static ArrayByteSource |
EMPTY
An empty source.
|
| Modifier and Type | Method and Description |
|---|---|
CharSource |
asCharSourceUtf8UsingBom()
Returns a
CharSource for the same bytes, converted to UTF-8 using a Byte-Order Mark if available. |
boolean |
contentEquals(ByteSource other) |
static ArrayByteSource |
copyOf(byte[] array)
Creates an instance, copying the array.
|
static ArrayByteSource |
copyOf(byte[] array,
int fromIndex)
Obtains an instance by copying part of an array.
|
static ArrayByteSource |
copyOf(byte[] array,
int fromIndexInclusive,
int toIndexExclusive)
Obtains an instance by copying part of an array.
|
long |
copyTo(OutputStream output) |
boolean |
equals(Object obj) |
static ArrayByteSource |
from(ByteSource other)
Creates an instance from another byte source.
|
static ArrayByteSource |
from(CheckedSupplier<InputStream> inputStreamSupplier)
Creates an instance from an input stream.
|
static ArrayByteSource |
fromBase64(String base64)
Creates an instance from a base-64 encoded string.
|
static ArrayByteSource |
fromHex(String hex)
Creates an instance from a hex encoded string, sometimes referred to as base-16.
|
HashCode |
hash(HashFunction hashFunction) |
int |
hashCode() |
boolean |
isEmpty()
Checks if the byte source is empty, throwing an unchecked exception.
|
org.joda.beans.MetaBean |
metaBean() |
static ArrayByteSource |
ofUnsafe(byte[] array)
Creates an instance, not copying the array.
|
static ArrayByteSource |
ofUtf8(String str)
Creates an instance from a string using UTF-8.
|
ByteArrayInputStream |
openBufferedStream() |
ByteArrayInputStream |
openStream() |
byte[] |
read()
Reads the source as a byte array, throwing an unchecked exception.
|
<T> T |
read(ByteProcessor<T> processor) |
byte[] |
readUnsafe()
Returns the underlying array.
|
String |
readUtf8()
Reads the source, converting to UTF-8.
|
String |
readUtf8UsingBom()
Reads the source, converting to UTF-8 using a Byte-Order Mark if available.
|
long |
size()
Gets the size of the byte source, throwing an unchecked exception.
|
Optional<Long> |
sizeIfKnown()
Gets the size, which is always known.
|
ArrayByteSource |
slice(long offset,
long length) |
ArrayByteSource |
toBase64()
Encodes the byte source using base-64.
|
String |
toBase64String()
Encodes the byte source using base-64, returning a string.
|
String |
toHexString()
Encodes the byte source using hex, sometimes referred to as base-16, returning a string.
|
ArrayByteSource |
toMd5()
Returns the MD5 hash of the bytes.
|
ArrayByteSource |
toSha512()
Returns the SHA-512 hash of the bytes.
|
String |
toString() |
asCharSourceUtf8, loadasCharSource, concat, concat, concat, copyTo, empty, wrappublic static final ArrayByteSource EMPTY
public static ArrayByteSource copyOf(byte[] array)
array - the array, copiedpublic static ArrayByteSource copyOf(byte[] array, int fromIndex)
The input array is copied and not mutated.
array - the array to copyfromIndex - the offset from the start of the arrayIndexOutOfBoundsException - if the index is invalidpublic static ArrayByteSource copyOf(byte[] array, int fromIndexInclusive, int toIndexExclusive)
The input array is copied and not mutated.
array - the array to copyfromIndexInclusive - the start index of the input array to copy fromtoIndexExclusive - the end index of the input array to copy toIndexOutOfBoundsException - if the index is invalidpublic static ArrayByteSource ofUnsafe(byte[] array)
This method is inherently unsafe as it relies on good behavior by callers. Callers must never make any changes to the passed in array after calling this method. Doing so would violate the immutability of this class.
array - the array, not copiedpublic static ArrayByteSource ofUtf8(String str)
str - the string to store using UTF-8public static ArrayByteSource from(ByteSource other)
other - the other byte sourceUncheckedIOException - if an IO error occurspublic static ArrayByteSource from(CheckedSupplier<InputStream> inputStreamSupplier)
This method use the supplier to open the input stream, extract the bytes and close the stream. It is intended that invoking the supplier opens the stream. It is not intended that an already open stream is supplied.
inputStreamSupplier - the supplier of the input streamUncheckedIOException - if an IO error occurspublic static ArrayByteSource fromBase64(String base64)
base64 - the base64 string to convertIllegalArgumentException - if the input is not Base64 encodedpublic static ArrayByteSource fromHex(String hex)
hex - the hex string to convertIllegalArgumentException - if the input is not hex encodedpublic org.joda.beans.MetaBean metaBean()
metaBean in interface org.joda.beans.Beanpublic byte[] readUnsafe()
This method is inherently unsafe as it relies on good behavior by callers. Callers must never make any changes to the array returned by this method. Doing so would violate the immutability of this class.
public String readUtf8()
readUtf8 in class BeanByteSourcepublic String readUtf8UsingBom()
readUtf8UsingBom in class BeanByteSourcepublic CharSource asCharSourceUtf8UsingBom()
CharSource for the same bytes, converted to UTF-8 using a Byte-Order Mark if available.asCharSourceUtf8UsingBom in class BeanByteSourceCharSourcepublic ArrayByteSource toMd5()
public ArrayByteSource toSha512()
public ArrayByteSource toBase64()
public String toBase64String()
Equivalent to toBase64().readUtf8().
public String toHexString()
public ByteArrayInputStream openStream()
openStream in class ByteSourcepublic ByteArrayInputStream openBufferedStream()
openBufferedStream in class ByteSourcepublic boolean isEmpty()
BeanByteSource
This overrides ByteSource to throw UncheckedIOException instead of IOException.
isEmpty in class BeanByteSourcepublic Optional<Long> sizeIfKnown()
sizeIfKnown in class ByteSourcepublic long size()
BeanByteSource
This overrides ByteSource to throw UncheckedIOException instead of IOException.
size in class BeanByteSourcepublic ArrayByteSource slice(long offset, long length)
slice in class ByteSourcepublic long copyTo(OutputStream output) throws IOException
copyTo in class ByteSourceIOExceptionpublic byte[] read()
BeanByteSource
This overrides ByteSource to throw UncheckedIOException instead of IOException.
read in class BeanByteSourcepublic <T> T read(ByteProcessor<T> processor) throws IOException
read in class ByteSourceIOExceptionpublic HashCode hash(HashFunction hashFunction)
hash in class ByteSourcepublic boolean contentEquals(ByteSource other) throws IOException
contentEquals in class ByteSourceIOExceptionCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.