Class PackedLong


  • public final class PackedLong
    extends Object
    Provides static methods to manipulate compact long representation. Compact long allow to stores unsigned long values up to 56 bits using a variable number of bytes from 1 to 8. The binary representations of this compact encoding has the interesting properties of maintaining correct order of values when compared.
    • Field Detail

      • MAX_COMPACT_SIZE

        public static final int MAX_COMPACT_SIZE
        Maximum size in bytes of a compact encoded value.
        See Also:
        Constant Field Values
      • COMPACTED_MAX_VALUE

        public static final long COMPACTED_MAX_VALUE
        Maximum value that can be stored with a compacted representation.
        See Also:
        Constant Field Values
    • Method Detail

      • writeCompactUnsigned

        public static int writeCompactUnsigned​(OutputStream os,
                                               long value)
                                        throws IOException
        Append the compact representation of the value into the OutputStream.
        Parameters:
        os - OutputStream where the compact representation will be written.
        value - Value to be encoded and written in the compact long format.
        Returns:
        Number of bytes which has been written in the buffer.
        Throws:
        IOException - if problem appear in the underlying OutputStream
      • getEncodedSize

        public static int getEncodedSize​(long value)
        Get the number of bytes required to store the given value using the compact long representation.
        Parameters:
        value - Value to get the compact representation's size.
        Returns:
        Number of bytes required to store the compact long representation of the value.
      • readCompactUnsignedLong

        public static long readCompactUnsignedLong​(InputStream is)
                                            throws IOException
        Decode and get the value of the compact long contained in the specified InputStream.
        Parameters:
        is - Stream where to read the compact unsigned long
        Returns:
        The long value.
        Throws:
        IOException - If the first byte cannot be read for any reason other than the end of the file, if the input stream has been closed, or if some other I/O error occurs.