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)
Encoder, EncoderFactory, BlockingBinaryEncoder, DirectBinaryEncoder
| Modifier and Type | Class 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 |
| Modifier and Type | Field and Description |
|---|---|
| private byte[] | |
| private int | |
| private int | |
| private BufferedBinaryEncoder. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public int | bytesBuffered()
Implements abstract org. |
| pack-priv BufferedBinaryEncoder | |
| 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. |
| private void | |
| public void | writeBoolean(boolean b)
Implements abstract org. |
| private void | |
| public void | |
| 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. |
| public void | writeFixed(ByteBuffer bytes)
Overrides org. |
| public void | |
| public void | |
| public void | |
| protected void | writeZero()
Implements abstract org. |
| buf | back to summary |
|---|---|
| private byte[] buf | |
| bulkLimit | back to summary |
|---|---|
| private int bulkLimit | |
| pos | back to summary |
|---|---|
| private int pos | |
| sink | back to summary |
|---|---|
| private BufferedBinaryEncoder. | |
| BufferedBinaryEncoder | back to summary |
|---|---|
| pack-priv BufferedBinaryEncoder(OutputStream out, int bufferSize) | |
| bytesBuffered | back to summary |
|---|---|
| public int bytesBuffered() Implements abstract org. Doc from org. Returns the number of bytes currently buffered by this encoder. If this Encoder does not buffer, this will always return zero.
Call
| |
| configure | back to summary |
|---|---|
| pack-priv BufferedBinaryEncoder configure(OutputStream out, int bufferSize) | |
| ensureBounds | back 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. | |
| flush | back to summary |
|---|---|
| public void flush() throws IOException Implements java. Doc from java. Flushes this stream by writing any buffered output to the underlying stream.
| |
| flushBuffer | back to summary |
|---|---|
| private void flushBuffer() throws IOException Flushes the internal buffer to the underlying output. Does not flush the underlying output. | |
| writeBoolean | back to summary |
|---|---|
| public void writeBoolean(boolean b) throws IOException Implements abstract org. Doc from org. Write a boolean value.
| |
| writeByte | back to summary |
|---|---|
| private void writeByte(int b) throws IOException | |
| writeDouble | back to summary |
|---|---|
| public void writeDouble(double d) throws IOException Implements abstract org. Doc from org. Write a double.
| |
| writeFixed | back to summary |
|---|---|
| public void writeFixed(byte[] bytes, int start, int len) throws IOException Implements abstract org. Doc from org. Writes a fixed size binary object.
| |
| writeFixed | back to summary |
|---|---|
| public void writeFixed(ByteBuffer bytes) throws IOException Overrides org. Doc from org. Writes a fixed from a ByteBuffer.
| |
| writeFloat | back to summary |
|---|---|
| public void writeFloat(float f) throws IOException Implements abstract org. Doc from org. Write a float.
| |
| writeInt | back to summary |
|---|---|
| public void writeInt(int n) throws IOException Implements abstract org. Doc from org. Writes a 32-bit integer.
| |
| writeLong | back to summary |
|---|---|
| public void writeLong(long n) throws IOException Implements abstract org. Doc from org. Write a 64-bit integer.
| |
| writeZero | back to summary |
|---|---|
| protected void writeZero() throws IOException Implements abstract org. Doc from org. Write a zero byte to the underlying output.
| |
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.
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| protected abstract void | |
| protected abstract void | |
| protected abstract void |
| ByteSink | back to summary |
|---|---|
| protected ByteSink() | |
| innerFlush | back to summary |
|---|---|
| protected abstract void innerFlush() throws IOException Flush the underlying output, if supported | |
| innerWrite | back to summary |
|---|---|
| protected abstract void innerWrite(byte[] bytes, int off, int len) throws IOException Write data from bytes, starting at off, for len bytes | |
| innerWrite | back to summary |
|---|---|
| protected abstract void innerWrite(ByteBuffer buff) throws IOException | |
| Modifier and Type | Field and Description |
|---|---|
| private final WritableByteChannel | |
| private final OutputStream |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| protected void | innerFlush()
Implements abstract org. |
| protected void | innerWrite(byte[] bytes, int off, int len)
Implements abstract org. |
| protected void | innerWrite(ByteBuffer buff)
Implements abstract org. |
| channel | back to summary |
|---|---|
| private final WritableByteChannel channel | |
| out | back to summary |
|---|---|
| private final OutputStream out | |
| OutputStreamSink | back to summary |
|---|---|
| private OutputStreamSink(OutputStream out) | |
| innerFlush | back to summary |
|---|---|
| protected void innerFlush() throws IOException Implements abstract org. Doc from org. Flush the underlying output, if supported
| |
| innerWrite | back to summary |
|---|---|
| protected void innerWrite(byte[] bytes, int off, int len) throws IOException Implements abstract org. Doc from org. Write data from bytes, starting at off, for len bytes
| |
| innerWrite | back to summary |
|---|---|
| protected void innerWrite(ByteBuffer buff) throws IOException Implements abstract org.
| |