Class ByteBufferIO


  • public final class ByteBufferIO
    extends Object
    Byte buffer I/O utilities. This code originally comes from Kryo Framework, author Nathan Sweet. Modified source to fit our needs.
    • Method Detail

      • packLong

        public static void packLong​(ByteBuffer out,
                                    long value)
        Packs non-negative long into output buffer. It will occupy 1-10 bytes depending on value (lower values occupy smaller space)

        This method originally comes from Kryo Framework, author Nathan Sweet.

        Parameters:
        out - the buffer to put value into, may not be null.
        value - the value to be serialized, must be non-negative
      • packInt

        public static void packInt​(ByteBuffer out,
                                   int value)
        Packs non-negative int into output buffer. It will occupy 1-5 bytes depending on value (lower values occupy smaller space)

        This method originally comes from Kryo Framework, author Nathan Sweet.

        Parameters:
        out - the buffer to put value into, may not be null.
        value - the value to be serialized, must be non-negative
      • packInt

        public static int packInt​(byte[] out,
                                  int value,
                                  int stPos)
        Packs non-negative int into output array. It will occupy 1-5 bytes depending on value (lower values occupy smaller space)

        This method originally comes from Kryo Framework, author Nathan Sweet.

        Parameters:
        out - the array to put value into, may not be null.
        value - the value to be serialized, must be non-negative
        stPos - the position in the output array to start writing at.
      • packInt

        @Deprecated
        public static void packInt​(ByteBufferStream out,
                                   int value)
        Deprecated.
        Packs non-negative long into output buffer stream. It will occupy 1-10 bytes depending on value (lower values occupy smaller space)

        This method originally comes from Kryo Framework, author Nathan Sweet.

        Parameters:
        out - the buffer to put value into, may not be null.
        value - the value to be serialized, must be non-negative
      • calcInt

        public static int calcInt​(int value)
        Calculates how many bytes packed value will occupy.
        Parameters:
        value - The value.
        Returns:
        the number of bytes the packed value will occupy.
      • unpackInt

        public static int unpackInt​(ByteBuffer is)
        Unpack positive int value from the input buffer.

        This method originally comes from Kryo Framework, author Nathan Sweet.

        Parameters:
        is - The input buffer, may not be null.
        Returns:
        The unpacked int value.
      • unpackLong

        public static long unpackLong​(ByteBuffer in)
        Unpack positive long value from the input buffer.

        This method originally comes from Kryo Framework, author Nathan Sweet.

        Parameters:
        in - The input buffer, may not be null.
        Returns:
        The unpacked long value.