org.apache.avro.io

## Class BufferedBinaryEncoder

- java.lang.Object
- - org.apache.avro.io.Encoder
  - - org.apache.avro.io.BinaryEncoder
    - - org.apache.avro.io.BufferedBinaryEncoder

- All Implemented Interfaces:
    Flushable
  Direct Known Subclasses:
    BlockingBinaryEncoder

      public class BufferedBinaryEncoder
      extends BinaryEncoder

  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`

- - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `bytesBuffered()` Returns the number of bytes currently buffered by this encoder.
    `void` | `flush()`
    `void` | `writeBoolean(boolean b)` Write a boolean value.
    `void` | `writeDouble(double d)` Write a double.
    `void` | `writeFixed(byte[] bytes, int start, int len)` Writes a fixed size binary object.
    `void` | `writeFixed(ByteBuffer bytes)` Writes a fixed from a ByteBuffer.
    `void` | `writeFloat(float f)` Write a float.
    `void` | `writeInt(int n)` Writes a 32-bit integer.
    `void` | `writeLong(long n)` Write a 64-bit integer.
    `protected void` | `writeZero()` Write a zero byte to the underlying output.

    - ### Methods inherited from class org.apache.avro.io.BinaryEncoder

      `setItemCount, startItem, writeArrayEnd, writeArrayStart, writeBytes, writeBytes, writeEnum, writeIndex, writeMapEnd, writeMapStart, writeNull, writeString, writeString`

    - ### Methods inherited from class org.apache.avro.io.Encoder

      `writeBytes, writeFixed, writeString`

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

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

- - ### Method Detail

    - #### flush

          public void flush()
                     throws IOException

      Throws:
        `IOException`

    - #### writeBoolean

          public void writeBoolean(boolean b)
                            throws IOException

      Description copied from class: `Encoder`
      Write a boolean value.
      Specified by:
        `writeBoolean` in class `Encoder`
      Throws:
        `IOException`

    - #### writeInt

          public void writeInt(int n)
                        throws IOException

      Description copied from class: `Encoder`
      Writes a 32-bit integer.
      Specified by:
        `writeInt` in class `Encoder`
      Throws:
        `IOException`

    - #### writeLong

          public void writeLong(long n)
                         throws IOException

      Description copied from class: `Encoder`
      Write a 64-bit integer.
      Specified by:
        `writeLong` in class `Encoder`
      Throws:
        `IOException`

    - #### writeFloat

          public void writeFloat(float f)
                          throws IOException

      Description copied from class: `Encoder`
      Write a float.
      Specified by:
        `writeFloat` in class `Encoder`
      Throws:
        `IOException`

    - #### writeDouble

          public void writeDouble(double d)
                           throws IOException

      Description copied from class: `Encoder`
      Write a double.
      Specified by:
        `writeDouble` in class `Encoder`
      Throws:
        `IOException`

    - #### writeFixed

          public void writeFixed(byte[] bytes,
                                 int start,
                                 int len)
                          throws IOException

      Description copied from class: `Encoder`
      Writes a fixed size binary object.
      Specified by:
        `writeFixed` in class `Encoder`
      Parameters:
        `bytes` - The contents to write
        `start` - The position within `bytes` where the contents start.
        `len` - The number of bytes to write.
      Throws:
        `IOException`

    - #### writeFixed

          public void writeFixed(ByteBuffer bytes)
                          throws IOException

      Description copied from class: `Encoder`
      Writes a fixed from a ByteBuffer.
      Overrides:
        `writeFixed` in class `Encoder`
      Throws:
        `IOException`

    - #### writeZero

          protected void writeZero()
                            throws IOException

      Description copied from class: `BinaryEncoder`
      Write a zero byte to the underlying output.
      Specified by:
        `writeZero` in class `BinaryEncoder`
      Throws:
        `IOException`

    - #### bytesBuffered

          public int bytesBuffered()

      Description copied from class: `BinaryEncoder`
      Returns the number of bytes currently buffered by this encoder. If this Encoder does not buffer, this will always return zero.

      Call `Flushable.flush()` to empty the buffer to the underlying output.
      Specified by:
        `bytesBuffered` in class `BinaryEncoder`

Copyright © 2009–2024 The Apache Software Foundation. All rights reserved.