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

public Class BufferedBinaryEncoder

extends BinaryEncoder
Class Inheritance
Known Direct Subclasses
org.apache.avro.io.BlockingBinaryEncoder
Imports
java.io.IOException, .OutputStream, java.nio.ByteBuffer, java.nio.channels.Channels, .WritableByteChannel, java.util.Objects, org.apache.avro.AvroRuntimeException

An Encoder for Avro's binary encoding.

This implementation buffers output to enhance performance. Output may not appear on the underlying output until flush() is called.

DirectBinaryEncoder can be used in place of this implementation if the buffering semantics are not desired, and the performance difference is acceptable.

To construct or reconfigure, use EncoderFactory#binaryEncoder(OutputStream, BinaryEncoder).

To change the buffer size, configure the factory instance used to create instances with EncoderFactory#configureBufferSize(int)

See Also
Encoder, EncoderFactory, BlockingBinaryEncoder, DirectBinaryEncoder

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
BufferedBinaryEncoder.ByteSink

ByteSink abstracts the destination of written data from the core workings of BinaryEncoder.

pack-priv static class

Field Summary

Modifier and TypeField and Description
private byte[]
private int
private int
private BufferedBinaryEncoder.ByteSink

Constructor Summary

AccessConstructor and Description
pack-priv
BufferedBinaryEncoder(OutputStream out, int bufferSize)

Method Summary

Modifier and TypeMethod and Description
public int
bytesBuffered()

Implements abstract org.apache.avro.io.BinaryEncoder.bytesBuffered.

Returns the number of bytes currently buffered by this encoder.
pack-priv BufferedBinaryEncoder
configure(OutputStream out, int bufferSize)

private void
ensureBounds(int num)

Ensures that the buffer has at least num bytes free to write to between its current position and the end.

public void
flush()

Implements java.io.Flushable.flush.

Flushes this stream by writing any buffered output to the underlying stream.
private void
flushBuffer()

Flushes the internal buffer to the underlying output.

public void
writeBoolean(boolean b)

Implements abstract org.apache.avro.io.Encoder.writeBoolean.

Write a boolean value.
private void
writeByte(int b)

public void
writeDouble(double d)

Implements abstract org.apache.avro.io.Encoder.writeDouble.

Write a double.
public void
writeFixed(byte[]
The contents to write
bytes
,
int
The position within bytes where the contents start.
start
,
int
The number of bytes to write.
len
)

Implements abstract org.apache.avro.io.Encoder.writeFixed.

Writes a fixed size binary object.
public void
writeFixed(ByteBuffer bytes)

Overrides org.apache.avro.io.Encoder.writeFixed.

Writes a fixed from a ByteBuffer.
public void
writeFloat(float f)

Implements abstract org.apache.avro.io.Encoder.writeFloat.

Write a float.
public void
writeInt(int n)

Implements abstract org.apache.avro.io.Encoder.writeInt.

Writes a 32-bit integer.
public void
writeLong(long n)

Implements abstract org.apache.avro.io.Encoder.writeLong.

Write a 64-bit integer.
protected void
writeZero()

Implements abstract org.apache.avro.io.BinaryEncoder.writeZero.

Write a zero byte to the underlying output.
Inherited from org.apache.avro.io.BinaryEncoder:
setItemCountstartItemwriteArrayEndwriteArrayStartwriteByteswriteByteswriteEnumwriteIndexwriteMapEndwriteMapStartwriteNullwriteStringwriteString

Field Detail

bufback to summary
private byte[] buf
bulkLimitback to summary
private int bulkLimit
posback to summary
private int pos
sinkback to summary
private BufferedBinaryEncoder.ByteSink sink

Constructor Detail

BufferedBinaryEncoderback to summary
pack-priv BufferedBinaryEncoder(OutputStream out, int bufferSize)

Method Detail

bytesBufferedback to summary
public int bytesBuffered()

Implements abstract org.apache.avro.io.BinaryEncoder.bytesBuffered.

Doc from org.apache.avro.io.BinaryEncoder.bytesBuffered.

Returns the number of bytes currently buffered by this encoder. If this Encoder does not buffer, this will always return zero.

Call flush() to empty the buffer to the underlying output.

Annotations
@Override
configureback to summary
pack-priv BufferedBinaryEncoder configure(OutputStream out, int bufferSize)
ensureBoundsback to summary
private void ensureBounds(int num) throws IOException

Ensures that the buffer has at least num bytes free to write to between its current position and the end. This will not expand the buffer larger than its current size, for writes larger than or near to the size of the buffer, we flush the buffer and write directly to the output, bypassing the buffer.

flushback to summary
public void flush() throws IOException

Implements java.io.Flushable.flush.

Doc from java.io.Flushable.flush.

Flushes this stream by writing any buffered output to the underlying stream.

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs
flushBufferback to summary
private void flushBuffer() throws IOException

Flushes the internal buffer to the underlying output. Does not flush the underlying output.

writeBooleanback to summary
public void writeBoolean(boolean b) throws IOException

Implements abstract org.apache.avro.io.Encoder.writeBoolean.

Doc from org.apache.avro.io.Encoder.writeBoolean.

Write a boolean value.

Annotations
@Override
writeByteback to summary
private void writeByte(int b) throws IOException
writeDoubleback to summary
public void writeDouble(double d) throws IOException

Implements abstract org.apache.avro.io.Encoder.writeDouble.

Doc from org.apache.avro.io.Encoder.writeDouble.

Write a double.

Annotations
@Override
writeFixedback to summary
public void writeFixed(byte[] bytes, int start, int len) throws IOException

Implements abstract org.apache.avro.io.Encoder.writeFixed.

Doc from org.apache.avro.io.Encoder.writeFixed.

Writes a fixed size binary object.

Parameters
bytes:byte[]

The contents to write

start:int

The position within bytes where the contents start.

len:int

The number of bytes to write.

Annotations
@Override
writeFixedback to summary
public void writeFixed(ByteBuffer bytes) throws IOException

Overrides org.apache.avro.io.Encoder.writeFixed.

Doc from org.apache.avro.io.Encoder.writeFixed.

Writes a fixed from a ByteBuffer.

Annotations
@Override
writeFloatback to summary
public void writeFloat(float f) throws IOException

Implements abstract org.apache.avro.io.Encoder.writeFloat.

Doc from org.apache.avro.io.Encoder.writeFloat.

Write a float.

Annotations
@Override
writeIntback to summary
public void writeInt(int n) throws IOException

Implements abstract org.apache.avro.io.Encoder.writeInt.

Doc from org.apache.avro.io.Encoder.writeInt.

Writes a 32-bit integer.

Annotations
@Override
writeLongback to summary
public void writeLong(long n) throws IOException

Implements abstract org.apache.avro.io.Encoder.writeLong.

Doc from org.apache.avro.io.Encoder.writeLong.

Write a 64-bit integer.

Annotations
@Override
writeZeroback to summary
protected void writeZero() throws IOException

Implements abstract org.apache.avro.io.BinaryEncoder.writeZero.

Doc from org.apache.avro.io.BinaryEncoder.writeZero.

Write a zero byte to the underlying output.

Annotations
@Override
org.apache.avro.io back to summary

private abstract Class BufferedBinaryEncoder.ByteSink

extends Object
Class Inheritance
Known Direct Subclasses
org.apache.avro.io.BufferedBinaryEncoder.OutputStreamSink

ByteSink abstracts the destination of written data from the core workings of BinaryEncoder.

Currently the only destination option is an OutputStream, but we may later want to handle other constructs or specialize for certain OutputStream Implementations such as ByteBufferOutputStream.

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected abstract void
innerFlush()

Flush the underlying output, if supported

protected abstract void
innerWrite(byte[] bytes, int off, int len)

Write data from bytes, starting at off, for len bytes

protected abstract void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ByteSinkback to summary
protected ByteSink()

Method Detail

innerFlushback to summary
protected abstract void innerFlush() throws IOException

Flush the underlying output, if supported

innerWriteback to summary
protected abstract void innerWrite(byte[] bytes, int off, int len) throws IOException

Write data from bytes, starting at off, for len bytes

innerWriteback to summary
protected abstract void innerWrite(ByteBuffer buff) throws IOException
org.apache.avro.io back to summary

pack-priv Class BufferedBinaryEncoder.OutputStreamSink

extends ByteSink
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final WritableByteChannel
private final OutputStream

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected void
innerFlush()

Implements abstract org.apache.avro.io.BufferedBinaryEncoder.ByteSink.innerFlush.

Flush the underlying output, if supported
protected void
innerWrite(byte[] bytes, int off, int len)

Implements abstract org.apache.avro.io.BufferedBinaryEncoder.ByteSink.innerWrite.

Write data from bytes, starting at off, for len bytes
protected void

Field Detail

channelback to summary
private final WritableByteChannel channel
outback to summary
private final OutputStream out

Constructor Detail

OutputStreamSinkback to summary
private OutputStreamSink(OutputStream out)

Method Detail

innerFlushback to summary
protected void innerFlush() throws IOException

Implements abstract org.apache.avro.io.BufferedBinaryEncoder.ByteSink.innerFlush.

Doc from org.apache.avro.io.BufferedBinaryEncoder.ByteSink.innerFlush.

Flush the underlying output, if supported

Annotations
@Override
innerWriteback to summary
protected void innerWrite(byte[] bytes, int off, int len) throws IOException

Implements abstract org.apache.avro.io.BufferedBinaryEncoder.ByteSink.innerWrite.

Doc from org.apache.avro.io.BufferedBinaryEncoder.ByteSink.innerWrite.

Write data from bytes, starting at off, for len bytes

Annotations
@Override
innerWriteback to summary
protected void innerWrite(ByteBuffer buff) throws IOException

Implements abstract org.apache.avro.io.BufferedBinaryEncoder.ByteSink.innerWrite.

Annotations
@Override