Package org.apache.beam.sdk.fn.stream
Class DataStreams.DataStreamDecoder<T>
java.lang.Object
org.apache.beam.sdk.fn.stream.DataStreams.DataStreamDecoder<T>
- All Implemented Interfaces:
Iterator<T>,PrefetchableIterator<T>
- Enclosing class:
DataStreams
public static class DataStreams.DataStreamDecoder<T>
extends Object
implements PrefetchableIterator<T>
An adapter which converts an
InputStream to a PrefetchableIterator of T
values using the specified Coder.
Note that this adapter follows the Beam Fn API specification for forcing values that decode consuming zero bytes to consuming exactly one byte.
Note that access to the underlying InputStream is lazy and will only be invoked on
first access to next(), hasNext(), isReady(), and prefetch().
Note that isReady() and prefetch() rely on non-empty ByteStrings being
returned via the underlying PrefetchableIterator otherwise the prefetch() will
seemingly make zero progress yet will actually advance through the empty pages.
-
Constructor Summary
ConstructorsConstructorDescriptionDataStreamDecoder(Coder<T> coder, PrefetchableIterator<org.apache.beam.vendor.grpc.v1p69p0.com.google.protobuf.ByteString> inputStream) -
Method Summary
Modifier and TypeMethodDescriptionSkips any remaining bytes in the currentByteStringmoving to the nextByteStringin the underlyingByteStringiteratorand decoding elements till at the next boundary.booleanhasNext()booleanisReady()Returnstrueif and only ifIterator.hasNext()andIterator.next()will not require an expensive operation.next()voidprefetch()If notPrefetchableIterator.isReady(), schedules the next expensive operation such that at some point in time in the futurePrefetchableIterator.isReady()will return true.voidremove()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
DataStreamDecoder
public DataStreamDecoder(Coder<T> coder, PrefetchableIterator<org.apache.beam.vendor.grpc.v1p69p0.com.google.protobuf.ByteString> inputStream)
-
-
Method Details
-
decodeFromChunkBoundaryToChunkBoundary
Skips any remaining bytes in the currentByteStringmoving to the nextByteStringin the underlyingByteStringiteratorand decoding elements till at the next boundary. -
isReady
public boolean isReady()Description copied from interface:PrefetchableIteratorReturnstrueif and only ifIterator.hasNext()andIterator.next()will not require an expensive operation.- Specified by:
isReadyin interfacePrefetchableIterator<T>
-
prefetch
public void prefetch()Description copied from interface:PrefetchableIteratorIf notPrefetchableIterator.isReady(), schedules the next expensive operation such that at some point in time in the futurePrefetchableIterator.isReady()will return true.- Specified by:
prefetchin interfacePrefetchableIterator<T>
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove()
-