@NotThreadSafe public final class StreamDataFileReader extends Object implements FileReader<PositionStreamEvent,Long>
StreamDataFileWriter.StreamDataFileWriter| Modifier and Type | Method and Description |
|---|---|
void |
close() |
static StreamDataFileReader |
create(com.google.common.io.InputSupplier<? extends SeekableInputStream> eventInputSupplier)
Opens a new
StreamDataFileReader with the given inputs. |
static StreamDataFileReader |
createByStartTime(com.google.common.io.InputSupplier<? extends SeekableInputStream> eventInputSupplier,
com.google.common.io.InputSupplier<? extends InputStream> indexInputSupplier,
long startTime)
Opens a new
StreamDataFileReader with the given inputs that starts reading events that are
written at or after the given timestamp. |
static StreamDataFileReader |
createWithOffset(com.google.common.io.InputSupplier<? extends SeekableInputStream> eventInputSupplier,
com.google.common.io.InputSupplier<? extends InputStream> indexInputSupplier,
long offset)
Opens a new
StreamDataFileReader with the given inputs, which starts reading events at a the smallest
event position that is larger than or equal to the given offset. |
Long |
getPosition()
Returns the position information.
|
void |
initialize()
Opens this reader to prepare for consumption.
|
int |
read(Collection<? super PositionStreamEvent> events,
int maxEvents,
long timeout,
TimeUnit unit)
Reads as much data as possible until maxEvents.
|
int |
read(Collection<? super PositionStreamEvent> events,
int maxEvents,
long timeout,
TimeUnit unit,
ReadFilter readFilter)
Reads as much data as possible that passes the given filter until maxEvents.
|
public static StreamDataFileReader create(com.google.common.io.InputSupplier<? extends SeekableInputStream> eventInputSupplier)
StreamDataFileReader with the given inputs.eventInputSupplier - An InputSupplier for providing the stream to read events.StreamDataFileReader.public static StreamDataFileReader createByStartTime(com.google.common.io.InputSupplier<? extends SeekableInputStream> eventInputSupplier, @Nullable com.google.common.io.InputSupplier<? extends InputStream> indexInputSupplier, long startTime)
StreamDataFileReader with the given inputs that starts reading events that are
written at or after the given timestamp.eventInputSupplier - An InputSupplier for providing the stream to read events.indexInputSupplier - An InputSupplier for providing the stream to read event index.startTime - Timestamp in milliseconds for the event time to start reading with.StreamDataFileReader.public static StreamDataFileReader createWithOffset(com.google.common.io.InputSupplier<? extends SeekableInputStream> eventInputSupplier, @Nullable com.google.common.io.InputSupplier<? extends InputStream> indexInputSupplier, long offset)
StreamDataFileReader with the given inputs, which starts reading events at a the smallest
event position that is larger than or equal to the given offset.eventInputSupplier - An InputSupplier for providing the stream to read events.indexInputSupplier - An InputSupplier for providing the stream to read event index.offset - An arbitrary event file offset.StreamDataFileReader.public Long getPosition()
PositionReportergetPosition in interface PositionReporter<Long><P>public void initialize()
throws IOException
read(java.util.Collection, int, long, java.util.concurrent.TimeUnit, co.cask.cdap.data.file.ReadFilter)
method would do the initialization if this method hasn't been called.initialize in interface FileReader<PositionStreamEvent,Long>IOException - If there is error initializing.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic int read(Collection<? super PositionStreamEvent> events, int maxEvents, long timeout, TimeUnit unit) throws IOException, InterruptedException
FileReaderread in interface FileReader<PositionStreamEvent,Long>events - Collection for storing data read.maxEvents - Maximum number of events to read.timeout - Maximum of time to spend on trying to read eventsunit - Unit for the timeout.0. If -1 is returned, meaning it reached EOF and all
sub-sequence call to this method will also return -1.IOException - If failed to read.InterruptedException - If the reading is interrupted.public int read(Collection<? super PositionStreamEvent> events, int maxEvents, long timeout, TimeUnit unit, ReadFilter readFilter) throws IOException, InterruptedException
FileReaderread in interface FileReader<PositionStreamEvent,Long>events - Collection for storing data read.maxEvents - Maximum number of events to read.timeout - Maximum of time to spend on trying to read eventsunit - Unit for the timeout.readFilter - Filter to apply during reading0. If -1 is returned, meaning it reached EOF and all
sub-sequence call to this method will also return -1.IOException - If failed to read.InterruptedException - If the reading is interrupted.Copyright © 2016 Cask Data, Inc. Licensed under the Apache License, Version 2.0.