@NotThreadSafe public class RandomAccessData extends java.lang.Object
InputStream
to this wrapper to
be used as an OutputStream
and vice versa. This wrapper also provides random access to
bytes stored within. This wrapper allows users to finely control the number of byte copies that
occur.
Anything stored within the in-memory buffer from offset size()
is considered
temporary unused storage.
Modifier and Type | Class and Description |
---|---|
static class |
RandomAccessData.RandomAccessDataCoder
A
Coder which encodes the valid parts of this stream. |
static class |
RandomAccessData.UnsignedLexicographicalComparator
A
Comparator that compares two byte arrays lexicographically. |
Modifier and Type | Field and Description |
---|---|
static RandomAccessData.UnsignedLexicographicalComparator |
UNSIGNED_LEXICOGRAPHICAL_COMPARATOR |
Constructor and Description |
---|
RandomAccessData()
Constructs a RandomAccessData with a default buffer size.
|
RandomAccessData(byte[] initialBuffer)
Constructs a RandomAccessData with the initial buffer.
|
RandomAccessData(int initialBufferSize)
Constructs a RandomAccessData with the given buffer size.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
array()
Returns the backing array.
|
java.io.InputStream |
asInputStream(int offset,
int length)
Returns an
InputStream wrapper which supplies the portion of this backing byte buffer
starting at offset and up to length bytes. |
java.io.OutputStream |
asOutputStream()
Returns an output stream which writes to the backing buffer from the current position.
|
RandomAccessData |
copy()
Returns a copy of this RandomAccessData.
|
boolean |
equals(java.lang.Object other) |
int |
hashCode() |
RandomAccessData |
increment()
Returns a RandomAccessData that is the smallest value of same length which is strictly greater
than this.
|
void |
readFrom(java.io.InputStream inStream,
int offset,
int length)
Reads
length bytes from the specified input stream writing them into the backing data
store starting at offset . |
void |
resetTo(int position)
Resets the end of the stream to the specified position.
|
int |
size()
Returns the number of bytes in the backing array that are valid.
|
java.lang.String |
toString() |
void |
writeTo(java.io.OutputStream out,
int offset,
int length)
Writes
length bytes starting at offset from the backing data store to the
specified output stream. |
public static final RandomAccessData.UnsignedLexicographicalComparator UNSIGNED_LEXICOGRAPHICAL_COMPARATOR
public RandomAccessData()
public RandomAccessData(byte[] initialBuffer)
public RandomAccessData(int initialBufferSize)
public RandomAccessData increment() throws java.io.IOException
The RandomAccessData.UnsignedLexicographicalComparator
supports comparing RandomAccessData
with support for positive infinitiy.
java.io.IOException
public byte[] array()
public int size()
public void resetTo(int position)
public java.io.OutputStream asOutputStream()
public java.io.InputStream asInputStream(int offset, int length)
InputStream
wrapper which supplies the portion of this backing byte buffer
starting at offset
and up to length
bytes. Note that the returned InputStream
is only a wrapper and any modifications to the underlying RandomAccessData
will be visible by the InputStream
.public void writeTo(java.io.OutputStream out, int offset, int length) throws java.io.IOException
length
bytes starting at offset
from the backing data store to the
specified output stream.java.io.IOException
public void readFrom(java.io.InputStream inStream, int offset, int length) throws java.io.IOException
length
bytes from the specified input stream writing them into the backing data
store starting at offset
.
Note that the in memory stream will be grown to ensure there is enough capacity.
java.io.IOException
public RandomAccessData copy() throws java.io.IOException
java.io.IOException
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object