Class PackedDataOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.lang.AutoCloseable

    class PackedDataOutputStream
    extends java.io.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 Summary

      Fields 
      Modifier and Type Field Description
      (package private) static int MAX_1BYTE  
      (package private) static int MAX_2BYTE  
      (package private) static int MAX_3BYTE  
      (package private) static int MAX_4BYTE  
      • Fields inherited from class java.io.DataOutputStream

        written
      • Fields inherited from class java.io.FilterOutputStream

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      PackedDataOutputStream​(java.io.OutputStream out)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void writePackedU32​(int i)
      Writes an unsigned integer in as few bytes as possible.
      • Methods inherited from class java.io.DataOutputStream

        flush, size, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
      • Methods inherited from class java.io.FilterOutputStream

        close, write
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.io.DataOutput

        write
    • Constructor Detail

      • PackedDataOutputStream

        public PackedDataOutputStream​(java.io.OutputStream out)
    • Method Detail

      • writePackedU32

        public void writePackedU32​(int i)
                            throws java.io.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:
        java.io.IOException - if any i/o error occurs