Top Description Inners Fields Constructors Methods
org.apache.avro.file

public Class DataFileStream<D>

extends Object
implements Iterator<D>, Iterable<D>, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable, java.util.Iterator
Known Direct Subclasses
org.apache.avro.file.DataFileReader
Imports
java.io.EOFException, .IOException, .InputStream, .Closeable, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.util.Arrays, .ArrayList, .Collections, .HashMap, .Iterator, .List, .Map, .NoSuchElementException, org.apache.avro.AvroRuntimeException, .InvalidAvroMagicException, .Schema, org.apache.avro.io.BinaryEncoder, .DecoderFactory, .BinaryDecoder, .DatumReader

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static class
DataFileStream.Header

A handle that can be used to reopen a DataFile without re-reading the header of the stream.

Field Summary

Modifier and TypeField and Description
private boolean
private DataFileStream.DataBlock
pack-priv ByteBuffer
pack-priv long
pack-priv long
private long
private Codec
pack-priv BinaryDecoder
datumIn

Secondary decoder, for datums.

private DataFileStream.Header
private DatumReader<D>
pack-priv byte[]
pack-priv BinaryDecoder
vin

Decoder on raw input stream.

Constructor Summary

AccessConstructor and Description
public
DataFileStream(InputStream in, DatumReader<D> reader)

Construct a reader for an input stream.

protected
DataFileStream(DatumReader<D> reader)

create an uninitialized DataFileStream

Method Summary

Modifier and TypeMethod and Description
protected void
public void
close()

Implements java.io.Closeable.close.

Close this reader.
public long
getBlockCount()

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

public long
getBlockSize()

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

public DataFileStream.Header
getHeader()

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

public byte[]
getMeta(String key)

Return the value of a metadata property.

public List<String>
getMetaKeys()

Return the list of keys in the metadata

public long
getMetaLong(String key)

Return the value of a metadata property.

public String
getMetaString(String key)

Return the value of a metadata property.

public Schema
getSchema()

Return the schema used in this file.

public boolean
hasNext()

Implements java.util.Iterator.hasNext.

True if more entries remain in this file.
pack-priv boolean
pack-priv void
initialize(InputStream in, byte[] magic)

Initialize the stream by reading from its head.

pack-priv void
initialize(DataFileStream.Header header)

Initialize the stream without reading from it.

public Iterator<D>
iterator()

Implements java.lang.Iterable.iterator.

Returns an iterator over entries in this file.
public D
next()

Implements java.util.Iterator.next.

Read the next datum in the file.
public D
next(D
an instance to reuse.
reuse
)

Read the next datum from the file.

public ByteBuffer
nextBlock()

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

pack-priv DataFileStream.DataBlock
pack-priv byte[]
public void
remove()

Overrides default java.util.Iterator.remove.

Not supported.
pack-priv Codec
pack-priv void
validateMagic(byte[] magic)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

availableBlockback to summary
private boolean availableBlock
blockback to summary
private DataFileStream.DataBlock block
blockBufferback to summary
pack-priv ByteBuffer blockBuffer
blockCountback to summary
pack-priv long blockCount
blockRemainingback to summary
pack-priv long blockRemaining
blockSizeback to summary
private long blockSize
codecback to summary
private Codec codec
datumInback to summary
pack-priv BinaryDecoder datumIn

Secondary decoder, for datums. (Different than vin for block segments.)

readerback to summary
private DatumReader<D> reader
syncBufferback to summary
pack-priv byte[] syncBuffer
vinback to summary
pack-priv BinaryDecoder vin

Decoder on raw input stream. (Used for metadata.)

Constructor Detail

DataFileStreamback to summary
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 java.io.BufferedInputStream is not necessary.

DataFileStreamback to summary
protected DataFileStream(DatumReader<D> reader) throws IOException

create an uninitialized DataFileStream

Method Detail

blockFinishedback to summary
protected void blockFinished() throws IOException
closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Close this reader.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.Closeable.close.

if an I/O error occurs

getBlockCountback to summary
public long getBlockCount()

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

getBlockSizeback to summary
public long getBlockSize()

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

getHeaderback to summary
public DataFileStream.Header getHeader()

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

getMetaback to summary
public byte[] getMeta(String key)

Return the value of a metadata property.

getMetaKeysback to summary
public List<String> getMetaKeys()

Return the list of keys in the metadata

getMetaLongback to summary
public long getMetaLong(String key)

Return the value of a metadata property.

getMetaStringback to summary
public String getMetaString(String key)

Return the value of a metadata property.

getSchemaback to summary
public Schema getSchema()

Return the schema used in this file.

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

True if more entries remain in this file.

Returns:boolean

Doc from java.util.Iterator.hasNext.

true if the iteration has more elements

Annotations
@Override
hasNextBlockback to summary
pack-priv boolean hasNextBlock()
initializeback to summary
pack-priv void initialize(InputStream in, byte[] magic) throws IOException

Initialize the stream by reading from its head.

initializeback to summary
pack-priv void initialize(DataFileStream.Header header) throws IOException

Initialize the stream without reading from it.

iteratorback to summary
public Iterator<D> iterator()

Implements java.lang.Iterable.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.

Returns:Iterator<D>

Doc from java.lang.Iterable.iterator.

an Iterator.

Annotations
@Override
nextback to summary
public D next()

Implements java.util.Iterator.next.

Read the next datum in the file.

Returns:D

Doc from java.util.Iterator.next.

the next element in the iteration

Annotations
@Override
Exceptions
NoSuchElementException:
if no more remain in the file.
nextback to summary
public D next(D reuse) throws IOException

Read the next datum from the file.

Parameters
reuse:D

an instance to reuse.

Exceptions
NoSuchElementException:
if no more remain in the file.
nextBlockback to summary
public ByteBuffer nextBlock() throws IOException

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

nextRawBlockback to summary
pack-priv DataFileStream.DataBlock nextRawBlock(DataFileStream.DataBlock reuse) throws IOException
readMagicback to summary
pack-priv byte[] readMagic() throws IOException
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Not supported.

Annotations
@Override
resolveCodecback to summary
pack-priv Codec resolveCodec()
validateMagicback to summary
pack-priv void validateMagic(byte[] magic) throws InvalidAvroMagicException
org.apache.avro.file back to summary

pack-priv Class DataFileStream.DataBlock

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private int
private byte[]
private boolean
private long
private int

Constructor Summary

AccessConstructor and Description
private
DataBlock(long numEntries, int blockSize)

pack-priv
DataBlock(ByteBuffer block, long numEntries)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv void
pack-priv ByteBuffer
pack-priv int
pack-priv byte[]
pack-priv long
pack-priv boolean
pack-priv void
setFlushOnWrite(boolean flushOnWrite)

pack-priv void
writeBlockTo(BinaryEncoder e, byte[] sync)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blockSizeback to summary
private int blockSize
databack to summary
private byte[] data
flushOnWriteback to summary
private boolean flushOnWrite
numEntriesback to summary
private long numEntries
offsetback to summary
private int offset

Constructor Detail

DataBlockback to summary
private DataBlock(long numEntries, int blockSize)
DataBlockback to summary
pack-priv DataBlock(ByteBuffer block, long numEntries)

Method Detail

compressUsingback to summary
pack-priv void compressUsing(Codec c) throws IOException
decompressUsingback to summary
pack-priv void decompressUsing(Codec c) throws IOException
getAsByteBufferback to summary
pack-priv ByteBuffer getAsByteBuffer()
getBlockSizeback to summary
pack-priv int getBlockSize()
getDataback to summary
pack-priv byte[] getData()
getNumEntriesback to summary
pack-priv long getNumEntries()
isFlushOnWriteback to summary
pack-priv boolean isFlushOnWrite()
setFlushOnWriteback to summary
pack-priv void setFlushOnWrite(boolean flushOnWrite)
writeBlockToback to summary
pack-priv void writeBlockTo(BinaryEncoder e, byte[] sync) throws IOException