org.apache.avro.file

## Class DataFileStream<D>

- java.lang.Object
- - org.apache.avro.file.DataFileStream<D>

All Implemented Interfaces:
  Closeable, AutoCloseable, Iterable<D>, Iterator<D>

Direct Known Subclasses:
  DataFileReader

    public class DataFileStream<D>
    extends Object
    implements Iterator<D>, Iterable<D>, Closeable

Streaming access to files written by `DataFileWriter`. Use `DataFileReader` for file-based input.

See Also:
  `DataFileWriter`

### Nested Class Summary

Nested Classes
`static class` `DataFileStream.Header` A handle that can be used to reopen a DataFile without re-reading the header of the stream.

### Constructor Summary

Constructors
`protected` `DataFileStream(DatumReader<D> reader)` create an uninitialized DataFileStream
`` `DataFileStream(InputStream in, DatumReader<D> reader)` Construct a reader for an input stream.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected void` `blockFinished()`
`void` `close()` Close this reader.
`long` `getBlockCount()` Expert: Return the count of items in the current block.
`long` `getBlockSize()` Expert: Return the size in bytes (uncompressed) of the current block.
`DataFileStream.Header` `getHeader()` A handle that can be used to reopen this stream without rereading the head.
`byte[]` `getMeta(String key)` Return the value of a metadata property.
`List<String>` `getMetaKeys()` Return the list of keys in the metadata
`long` `getMetaLong(String key)` Return the value of a metadata property.
`String` `getMetaString(String key)` Return the value of a metadata property.
`Schema` `getSchema()` Return the schema used in this file.
`boolean` `hasNext()` True if more entries remain in this file.
`Iterator<D>` `iterator()` Returns an iterator over entries in this file.
`D` `next()` Read the next datum in the file.
`D` `next(D reuse)` Read the next datum from the file.
`ByteBuffer` `nextBlock()` Expert: Return the next block in the file, as binary-encoded data.
`void` `remove()` Not supported.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.util.Iterator

`forEachRemaining`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Constructor Detail

#### DataFileStream

    public DataFileStream(InputStream in,
                          DatumReader<D> reader)
                   throws IOException

Construct a reader for an input stream. For file-based input, use `DataFileReader`. This will buffer, wrapping with a `BufferedInputStream` is not necessary.

Throws:
  `IOException`

#### DataFileStream

    protected DataFileStream(DatumReader<D> reader)
                      throws IOException

create an uninitialized DataFileStream

Throws:
  `IOException`

### Method Detail

#### getHeader

    public DataFileStream.Header getHeader()

A handle that can be used to reopen this stream without rereading the head.

#### getSchema

    public Schema getSchema()

Return the schema used in this file.

#### getMetaKeys

    public List<String> getMetaKeys()

Return the list of keys in the metadata

#### getMeta

    public byte[] getMeta(String key)

Return the value of a metadata property.

#### getMetaString

    public String getMetaString(String key)

Return the value of a metadata property.

#### getMetaLong

    public long getMetaLong(String key)

Return the value of a metadata property.

#### iterator

    public Iterator<D> iterator()

Returns an iterator over entries in this file. Note that this iterator is shared with other users of the file: it does not contain a separate pointer into the file.

Specified by:
  `iterator` in interface `Iterable<D>`

#### hasNext

    public boolean hasNext()

True if more entries remain in this file.

Specified by:
  `hasNext` in interface `Iterator<D>`

#### next

    public D next()

Read the next datum in the file.

Specified by:
  `next` in interface `Iterator<D>`
Throws:
  `NoSuchElementException` - if no more remain in the file.

#### next

    public D next(D reuse)
           throws IOException

Read the next datum from the file.

Parameters:
  `reuse` - an instance to reuse.
Throws:
  `NoSuchElementException` - if no more remain in the file.
  `IOException`

#### nextBlock

    public ByteBuffer nextBlock()
                         throws IOException

Expert: Return the next block in the file, as binary-encoded data.

Throws:
  `IOException`

#### getBlockCount

    public long getBlockCount()

Expert: Return the count of items in the current block.

#### getBlockSize

    public long getBlockSize()

Expert: Return the size in bytes (uncompressed) of the current block.

#### blockFinished

    protected void blockFinished()
                          throws IOException

Throws:
  `IOException`

#### remove

    public void remove()

Not supported.

Specified by:
  `remove` in interface `Iterator<D>`

#### close

    public void close()
               throws IOException

Close this reader.

Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `AutoCloseable`
Throws:
  `IOException`