Class RandomAccessData
- java.lang.Object
-
- org.apache.beam.runners.dataflow.util.RandomAccessData
-
@NotThreadSafe public class RandomAccessData extends java.lang.ObjectAn 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 anInputStreamto this wrapper to be used as anOutputStreamand 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 Classes Modifier and Type Class Description static classRandomAccessData.RandomAccessDataCoderACoderwhich encodes the valid parts of this stream.static classRandomAccessData.UnsignedLexicographicalComparatorAComparatorthat compares two byte arrays lexicographically.
-
Field Summary
Fields Modifier and Type Field Description static RandomAccessData.UnsignedLexicographicalComparatorUNSIGNED_LEXICOGRAPHICAL_COMPARATOR
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]array()Returns the backing array.java.io.InputStreamasInputStream(int offset, int length)Returns anInputStreamwrapper which supplies the portion of this backing byte buffer starting atoffsetand up tolengthbytes.java.io.OutputStreamasOutputStream()Returns an output stream which writes to the backing buffer from the current position.RandomAccessDatacopy()Returns a copy of this RandomAccessData.booleanequals(@Nullable java.lang.Object other)inthashCode()RandomAccessDataincrement()Returns a RandomAccessData that is the smallest value of same length which is strictly greater than this.voidreadFrom(java.io.InputStream inStream, int offset, int length)Readslengthbytes from the specified input stream writing them into the backing data store starting atoffset.voidresetTo(int position)Resets the end of the stream to the specified position.intsize()Returns the number of bytes in the backing array that are valid.java.lang.StringtoString()voidwriteTo(java.io.OutputStream out, int offset, int length)Writeslengthbytes starting atoffsetfrom the backing data store to the specified output stream.
-
-
-
Field Detail
-
UNSIGNED_LEXICOGRAPHICAL_COMPARATOR
public static final RandomAccessData.UnsignedLexicographicalComparator UNSIGNED_LEXICOGRAPHICAL_COMPARATOR
-
-
Constructor Detail
-
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 Detail
-
increment
public RandomAccessData increment() throws java.io.IOException
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.UnsignedLexicographicalComparatorsupports comparingRandomAccessDatawith support for positive infinity.- Throws:
java.io.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
public java.io.OutputStream 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
public java.io.InputStream asInputStream(int offset, int length)Returns anInputStreamwrapper which supplies the portion of this backing byte buffer starting atoffsetand up tolengthbytes. Note that the returnedInputStreamis only a wrapper and any modifications to the underlyingRandomAccessDatawill be visible by theInputStream.
-
writeTo
public void writeTo(java.io.OutputStream out, int offset, int length) throws java.io.IOExceptionWriteslengthbytes starting atoffsetfrom the backing data store to the specified output stream.- Throws:
java.io.IOException
-
readFrom
public void readFrom(java.io.InputStream inStream, int offset, int length) throws java.io.IOExceptionReadslengthbytes 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:
java.io.IOException
-
copy
public RandomAccessData copy() throws java.io.IOException
Returns a copy of this RandomAccessData.- Throws:
java.io.IOException
-
equals
public boolean equals(@Nullable java.lang.Object other)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-