Class RandomAccessData
java.lang.Object
org.apache.beam.runners.dataflow.util.RandomAccessData
An elastic-sized byte array which allows you to manipulate it as a stream, or access it directly.
This allows for a quick succession of moving bytes from an
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
ACoder
which encodes the valid parts of this stream.static final class
AComparator
that compares two byte arrays lexicographically. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs 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. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
array()
Returns the backing array.asInputStream
(int offset, int length) Returns anInputStream
wrapper which supplies the portion of this backing byte buffer starting atoffset
and up tolength
bytes.Returns an output stream which writes to the backing buffer from the current position.copy()
Returns a copy of this RandomAccessData.boolean
int
hashCode()
Returns a RandomAccessData that is the smallest value of same length which is strictly greater than this.void
readFrom
(InputStream inStream, int offset, int length) Readslength
bytes from the specified input stream writing them into the backing data store starting atoffset
.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.toString()
void
writeTo
(OutputStream out, int offset, int length) Writeslength
bytes starting atoffset
from the backing data store to the specified output stream.
-
Field Details
-
UNSIGNED_LEXICOGRAPHICAL_COMPARATOR
public static final RandomAccessData.UnsignedLexicographicalComparator UNSIGNED_LEXICOGRAPHICAL_COMPARATOR
-
-
Constructor Details
-
RandomAccessData
public RandomAccessData()Constructs a RandomAccessData with a default buffer size. -
RandomAccessData
public RandomAccessData(byte[] initialBuffer) Constructs a RandomAccessData with the initial buffer. -
RandomAccessData
public RandomAccessData(int initialBufferSize) Constructs a RandomAccessData with the given buffer size.
-
-
Method Details
-
increment
Returns a RandomAccessData that is the smallest value of same length which is strictly greater than this. Note that if this is empty or is all 0xFF then a token value of positive infinity is returned.The
RandomAccessData.UnsignedLexicographicalComparator
supports comparingRandomAccessData
with support for positive infinity.- Throws:
IOException
-
array
public byte[] array()Returns the backing array. -
size
public int size()Returns the number of bytes in the backing array that are valid. -
resetTo
public void resetTo(int position) Resets the end of the stream to the specified position. -
asOutputStream
Returns an output stream which writes to the backing buffer from the current position. Note that the internal buffer will grow as required to accommodate all data written. -
asInputStream
Returns anInputStream
wrapper which supplies the portion of this backing byte buffer starting atoffset
and up tolength
bytes. Note that the returnedInputStream
is only a wrapper and any modifications to the underlyingRandomAccessData
will be visible by theInputStream
. -
writeTo
Writeslength
bytes starting atoffset
from the backing data store to the specified output stream.- Throws:
IOException
-
readFrom
Readslength
bytes from the specified input stream writing them into the backing data store starting atoffset
.Note that the in memory stream will be grown to ensure there is enough capacity.
- Throws:
IOException
-
copy
Returns a copy of this RandomAccessData.- Throws:
IOException
-
equals
-
hashCode
public int hashCode() -
toString
-