Package org.apache.avro.file
Class DataFileReader<D>
java.lang.Object
org.apache.avro.file.DataFileStream<D>
org.apache.avro.file.DataFileReader<D>
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<D>
,Iterator<D>
,FileReader<D>
Random access to files written with
DataFileWriter
.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.avro.file.DataFileStream
DataFileStream.Header
-
Constructor Summary
ModifierConstructorDescriptionDataFileReader
(File file, DatumReader<D> reader) Construct a reader for a file.DataFileReader
(SeekableInput sin, DatumReader<D> reader) Construct a reader for a file.protected
DataFileReader
(SeekableInput sin, DatumReader<D> reader, boolean closeOnError, byte[] magic) Construct a reader for a file.protected
DataFileReader
(SeekableInput sin, DatumReader<D> reader, DataFileStream.Header header) Construct using aDataFileStream.Header
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
static <D> FileReader
<D> openReader
(File file, DatumReader<D> reader) Open a reader for a file.static <D> FileReader
<D> openReader
(SeekableInput in, DatumReader<D> reader) Open a reader for a file.static <D> DataFileReader
<D> openReader
(SeekableInput in, DatumReader<D> reader, DataFileStream.Header header, boolean sync) Construct a reader for a file at the current position of the input, without reading the header.boolean
pastSync
(long position) Return true if past the next synchronization point after a position.long
Return the last synchronization point before our current position.void
seek
(long position) Move to a specific, known synchronization point, one returned fromDataFileWriter.sync()
while writing.void
sync
(long position) Move to the next synchronization point after a position.long
tell()
Return the current position in the input.Methods inherited from class org.apache.avro.file.DataFileStream
close, getBlockCount, getBlockSize, getHeader, getMeta, getMetaKeys, getMetaLong, getMetaString, getSchema, hasNext, iterator, next, next, nextBlock, remove
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.avro.file.FileReader
getSchema, next
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Constructor Details
-
DataFileReader
Construct a reader for a file. For example,if you want to read a file record,you need to close the resource. You can use try-with-resource as follows:try (FileReader
dataFileReader = DataFileReader.openReader(file,datumReader)) { //Consume the reader } catch (IOException e) { throw new RunTimeIOException(e,"Failed to read metadata for file: %s", file); } - Throws:
IOException
-
DataFileReader
Construct a reader for a file. For example,if you want to read a file record,you need to close the resource. You can use try-with-resource as follows:try (FileReader
dataFileReader = DataFileReader.openReader(file,datumReader)) { //Consume the reader } catch (IOException e) { throw new RunTimeIOException(e,"Failed to read metadata for file: %s", file); } - Throws:
IOException
-
DataFileReader
protected DataFileReader(SeekableInput sin, DatumReader<D> reader, boolean closeOnError, byte[] magic) throws IOException Construct a reader for a file. Please close resource files yourself.- Throws:
IOException
-
DataFileReader
protected DataFileReader(SeekableInput sin, DatumReader<D> reader, DataFileStream.Header header) throws IOException - Throws:
IOException
-
-
Method Details
-
openReader
Open a reader for a file.- Throws:
IOException
-
openReader
public static <D> FileReader<D> openReader(SeekableInput in, DatumReader<D> reader) throws IOException Open a reader for a file.- Throws:
IOException
-
openReader
public static <D> DataFileReader<D> openReader(SeekableInput in, DatumReader<D> reader, DataFileStream.Header header, boolean sync) throws IOException Construct a reader for a file at the current position of the input, without reading the header.- Parameters:
sync
- True to read forward to the next sync point after opening, false to assume that the input is already at a valid sync point.- Throws:
IOException
-
seek
Move to a specific, known synchronization point, one returned fromDataFileWriter.sync()
while writing. If synchronization points were not saved while writing a file, usesync(long)
instead.- Throws:
IOException
-
sync
Move to the next synchronization point after a position. To process a range of file entires, call this with the starting position, then checkpastSync(long)
with the end point before each call toDataFileStream.next()
.- Specified by:
sync
in interfaceFileReader<D>
- Throws:
IOException
-
blockFinished
- Overrides:
blockFinished
in classDataFileStream<D>
- Throws:
IOException
-
previousSync
public long previousSync()Return the last synchronization point before our current position. -
pastSync
Return true if past the next synchronization point after a position.- Specified by:
pastSync
in interfaceFileReader<D>
- Throws:
IOException
-
tell
Description copied from interface:FileReader
Return the current position in the input.- Specified by:
tell
in interfaceFileReader<D>
- Throws:
IOException
-