Class PackedDataOutputStream

All Implemented Interfaces:
Closeable, DataOutput, Flushable, AutoCloseable

class PackedDataOutputStream extends DataOutputStream
An output stream that can pack integers into as few bytes as possible. PackedDataOutputStream

Thread-Safety

This class is not thread-safe can not be shared between threads.
  • Field Details

  • Constructor Details

    • PackedDataOutputStream

      public PackedDataOutputStream(OutputStream out)
  • Method Details

    • writePackedU32

      public void writePackedU32(int i) throws IOException
      Writes an unsigned integer in as few bytes as possible. Every byte uses the first bit as a control bit to signal when there are additional bytes to be read on the receiving end. The remaining seven bits are data. Depending on the size of the number one to five bytes may be written. The bytes are written in network-order (big endian)

      Note that a signed integer can still be used, but due to two's compliment, all negative values will be written as five bytes

      Parameters:
      i - the integer to pack and write
      Throws:
      IOException - if any i/o error occurs