Interface BitOutput

All Known Implementing Classes:
ByteOutputAdapter

public interface BitOutput
An interface for writing values of arbitrary number of bits.
Author:
Jin Kwon <jinahya_at_gmail.com>
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    align(int bytes)
    Aligns to specified number of bytes by padding required number of zero-bits.
    void
    Resets the total number of bytes written so far to 0.
    default void
    skip(int bits)
    Writes specified number of zero-bits.
    default void
    writeBoolean(boolean value)
    Writes specified boolean value.
    default void
    writeByte(boolean unsigned, int size, byte value)
    Writes specified byte value of specified number of bits.
    default void
    writeChar(int size, char value)
    Writes specified char value of specified number of bits.
    default void
    writeDouble(int exponentSize, int significandSize, double value)
    Writes specified float value with specified exponent size and significand size.
    default void
    writeFloat(int exponentSize, int significandSize, float value)
    Writes specified float value with specified exponent size and significand size.
    void
    writeInt(boolean unsigned, int size, int value)
    Writes specified int value of specified number of bits.
    default void
    writeLong(boolean unsigned, int size, long value)
    Writes specified long value of specified number of bits.
    default <T> void
    writeObject(BitWriter<? super T> writer, T value)
    Writes specified value using specified writer.
    default void
    writeShort(boolean unsigned, int size, short value)
    Writes specified short value of specified number of bits.
  • Method Details

    • writeBoolean

      default void writeBoolean(boolean value) throws IOException
      Writes specified boolean value.
      Parameters:
      value - the value to write.
      Throws:
      IOException - if an I/O error occurs.
      Implementation Requirements:
      The default implementation writes a 1-bit unsigned int value(0b1 for true, 0b0 for false) for the value.
    • writeByte

      default void writeByte(boolean unsigned, int size, byte value) throws IOException
      Writes specified byte value of specified number of bits.
      Parameters:
      unsigned - a flag for indicating unsigned value; true for unsigned, false for signed.
      size - the number of bits to write; between 1 and (8 - (unsigned ? 1: 0)), both inclusive.
      value - the value to write.
      Throws:
      IOException - if an I/O error occurs.
      Implementation Requirements:
      The default implementation invokes writeInt(boolean, int, int) with given arguments.
    • writeShort

      default void writeShort(boolean unsigned, int size, short value) throws IOException
      Writes specified short value of specified number of bits.
      Parameters:
      unsigned - a flag for indicating unsigned value; true for unsigned, false for signed.
      size - the number of bits to write; between 1 and (16 - (unsigned ? 1 : 0)), both inclusive.
      value - the value to write.
      Throws:
      IOException - if an I/O error occurs.
      Implementation Requirements:
      The default implementation invokes writeInt(boolean, int, int) method with given arguments.
    • writeInt

      void writeInt(boolean unsigned, int size, int value) throws IOException
      Writes specified int value of specified number of bits.
      Parameters:
      unsigned - a flag for indicating an unsigned value; true for unsigned, false for signed.
      size - the number of bits to write; between 1 and (32 - (unsigned ? 1 : 0)), both inclusive.
      value - the value to write.
      Throws:
      IOException - if an I/O error occurs.
    • writeLong

      default void writeLong(boolean unsigned, int size, long value) throws IOException
      Writes specified long value of specified number of bits.
      Parameters:
      unsigned - a flag for indicating unsigned value; true for unsigned, false for signed.
      size - the number of bits to write; between 1 and (64 - (unsigned ? 1 : 0)), both inclusive.
      value - the value to write.
      Throws:
      IOException - if an I/O error occurs.
    • writeChar

      default void writeChar(int size, char value) throws IOException
      Writes specified char value of specified number of bits.
      Parameters:
      size - the number of bits to write; between 1 and 16, both inclusive.
      value - the value to write.
      Throws:
      IOException - if an I/O error occurs.
      Implementation Requirements:
      The default implementation invokes writeInt(boolean, int, int) method with given arguments.
    • writeFloat

      default void writeFloat(int exponentSize, int significandSize, float value) throws IOException
      Writes specified float value with specified exponent size and significand size.
      Parameters:
      exponentSize - the number of lower exponent bits to write; between 1 and 8, both inclusive.
      significandSize - the number of left-most significand bits to write; between 1 and 23, both inclusive.
      value - the value to write.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • writeDouble

      default void writeDouble(int exponentSize, int significandSize, double value) throws IOException
      Writes specified float value with specified exponent size and significand size.
      Parameters:
      exponentSize - the number of lower exponent bits to write; between 1 and 11, both inclusive.
      significandSize - the number of left-most significand bits to write; between 1 and 52, both inclusive.
      value - the value to write.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • writeObject

      default <T> void writeObject(BitWriter<? super T> writer, T value) throws IOException
      Writes specified value using specified writer.
      Type Parameters:
      T - value type parameter
      Parameters:
      writer - the writer.
      value - the value to write.
      Throws:
      IOException - if an I/O error occurs.
      Implementation Requirements:
      The default implementation invokes BitWriter.write(BitOutput, Object) method on writer with this and value.
    • skip

      default void skip(int bits) throws IOException
      Writes specified number of zero-bits.
      Parameters:
      bits - the number of zero bits to write; must be positive.
      Throws:
      IllegalArgumentException - if bits is not positive.
      IOException - if an I/O error occurs.
      See Also:
    • align

      long align(int bytes) throws IOException
      Aligns to specified number of bytes by padding required number of zero-bits.
      Parameters:
      bytes - the number of bytes to align; must be positive.
      Returns:
      the number of zero-bits padded while aligning; non-negative, always.
      Throws:
      IllegalArgumentException - if bytes is not positive.
      IOException - if an I/O error occurs.
    • reset

      void reset()
      Resets the total number of bytes written so far to 0.
      Throws:
      IllegalStateException - if this input is not aligned.