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)
Obtains 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)
Obtains an instance from another byte source.
|
static ArrayByteSource |
from(CheckedSupplier<InputStream> inputStreamSupplier)
Obtains an instance from an input stream.
|
static ArrayByteSource |
from(InputStream inputStream)
Obtains an instance from an input stream.
|
static ArrayByteSource |
from(InputStream inputStream,
int expectedSize)
Obtains an instance from an input stream, specifying the expected size.
|
static ArrayByteSource |
fromBase64(String base64)
Obtains an instance from a base-64 encoded string.
|
static ArrayByteSource |
fromHex(String hex)
Obtains an instance from a hex encoded string, sometimes referred to as base-16.
|
Optional<String> |
getFileName()
Gets the file name of the source.
|
HashCode |
hash(HashFunction hashFunction) |
int |
hashCode() |
boolean |
isEmpty()
Checks if the byte source is empty, throwing an unchecked exception.
|
ArrayByteSource |
load()
Loads the content of the byte source into memory.
|
org.joda.beans.MetaBean |
metaBean() |
static ArrayByteSource |
ofUnsafe(byte[] array)
Obtains an instance, not copying the array.
|
static ArrayByteSource |
ofUtf8(String str)
Obtains 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()
Deprecated.
|
ArrayByteSource |
toSha512()
Deprecated.
|
String |
toString() |
ArrayByteSource |
withFileName(String fileName)
Returns an instance with the file name updated.
|
asCharSourceUtf8, toHash, toHashStringasCharSource, 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 from(InputStream inputStream) throws IOException
This method uses an already open input stream, extracting the bytes. The stream is not closed - that is the responsibility of the caller.
inputStream - the open input stream, which will not be closedIOException - if an IO error occurspublic static ArrayByteSource from(InputStream inputStream, int expectedSize) throws IOException
This method uses an already open input stream, extracting the bytes. The stream is not closed - that is the responsibility of the caller.
inputStream - the open input stream, which will not be closedexpectedSize - the expected size of the input, not negativeIOException - 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 Optional<String> getFileName()
BeanByteSourceMost sources originate from a file-based location. This is captured and returned here where available.
getFileName in class BeanByteSourcepublic ArrayByteSource withFileName(String fileName)
If a path is passed in, only the file name is retained.
fileName - the file name, an empty string can be used to remove the file namepublic 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 HashCode hash(HashFunction hashFunction)
hash in class BeanByteSource@Deprecated public ArrayByteSource toMd5()
BeanByteSource.toHash(HashFunction)The returned hash is in byte form.
@Deprecated public ArrayByteSource toSha512()
BeanByteSource.toHash(HashFunction)public ArrayByteSource toBase64()
toBase64 in class BeanByteSourcepublic String toBase64String()
Equivalent to toBase64().readUtf8().
toBase64String in class BeanByteSourcepublic 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 boolean contentEquals(ByteSource other) throws IOException
contentEquals in class ByteSourceIOExceptionpublic ArrayByteSource load()
BeanByteSourceload in class BeanByteSourceCopyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.