org.apache.avro.file
Class DataFileReader<D>

java.lang.Object
  extended by org.apache.avro.file.DataFileStream<D>
      extended by org.apache.avro.file.DataFileReader<D>
All Implemented Interfaces:
Closeable, Iterable<D>, Iterator<D>, FileReader<D>

public class DataFileReader<D>
extends DataFileStream<D>
implements FileReader<D>

Random access to files written with DataFileWriter.

See Also:
DataFileWriter

Constructor Summary
DataFileReader(File file, DatumReader<D> reader)
          Construct a reader for a file.
DataFileReader(SeekableInput sin, DatumReader<D> reader)
          Construct a reader for a file.
 
Method Summary
protected  void blockFinished()
           
 boolean pastSync(long position)
          Return true if past the next synchronization point after a position.
 long previousSync()
          Return the last synchronization point before our current position.
 void seek(long position)
          Move to a specific, known synchronization point, one returned from DataFileWriter.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, getMeta, 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.util.Iterator
hasNext, next, remove
 
Methods inherited from interface java.lang.Iterable
iterator
 
Methods inherited from interface java.io.Closeable
close
 

Constructor Detail

DataFileReader

public DataFileReader(File file,
                      DatumReader<D> reader)
               throws IOException
Construct a reader for a file.

Throws:
IOException

DataFileReader

public DataFileReader(SeekableInput sin,
                      DatumReader<D> reader)
               throws IOException
Construct a reader for a file.

Throws:
IOException
Method Detail

seek

public void seek(long position)
          throws IOException
Move to a specific, known synchronization point, one returned from DataFileWriter.sync() while writing. If synchronization points were not saved while writing a file, use {#sync(long)} instead.

Throws:
IOException

sync

public void sync(long position)
          throws IOException
Move to the next synchronization point after a position. To process a range of file entires, call this with the starting position, then check pastSync(long) with the end point before each call to DataFileStream.next().

Specified by:
sync in interface FileReader<D>
Throws:
IOException

blockFinished

protected void blockFinished()
                      throws IOException
Overrides:
blockFinished in class DataFileStream<D>
Throws:
IOException

previousSync

public long previousSync()
Return the last synchronization point before our current position.


pastSync

public boolean pastSync(long position)
                 throws IOException
Return true if past the next synchronization point after a position.

Specified by:
pastSync in interface FileReader<D>
Throws:
IOException

tell

public long tell()
          throws IOException
Description copied from interface: FileReader
Return the current position in the input.

Specified by:
tell in interface FileReader<D>
Throws:
IOException


Copyright © 2010 The Apache Software Foundation