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:
java.util.Iterator<T>,PrefetchableIterator<T>
- Enclosing class:
- DataStreams
public static class DataStreams.DataStreamDecoder<T> extends java.lang.Object implements PrefetchableIterator<T>
An adapter which converts anInputStreamto aPrefetchableIteratorofTvalues using the specifiedCoder.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
InputStreamis lazy and will only be invoked on first access tonext(),hasNext(),isReady(), andprefetch().Note that
isReady()andprefetch()rely on non-emptyByteStrings being returned via the underlyingPrefetchableIteratorotherwise theprefetch()will seemingly make zero progress yet will actually advance through the empty pages.
-
-
Constructor Summary
Constructors Constructor Description DataStreamDecoder(org.apache.beam.sdk.coders.Coder<T> coder, PrefetchableIterator<org.apache.beam.vendor.grpc.v1p48p1.com.google.protobuf.ByteString> inputStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<T>decodeFromChunkBoundaryToChunkBoundary()Skips 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.Tnext()voidprefetch()If notPrefetchableIterator.isReady(), schedules the next expensive operation such that at some point in time in the futurePrefetchableIterator.isReady()will return true.voidremove()
-
-
-
Constructor Detail
-
DataStreamDecoder
public DataStreamDecoder(org.apache.beam.sdk.coders.Coder<T> coder, PrefetchableIterator<org.apache.beam.vendor.grpc.v1p48p1.com.google.protobuf.ByteString> inputStream)
-
-
Method Detail
-
decodeFromChunkBoundaryToChunkBoundary
public java.util.List<T> 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()
- Specified by:
hasNextin interfacejava.util.Iterator<T>
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<T>
-
-