Class VByte

java.lang.Object
org.eclipse.rdf4j.rio.hdt.VByte

public class VByte extends Object
Variable byte encoding for numbers.

A variable number of bytes is used to encode (unsigned) numeric values, the first bit (MSB) of each byte indicates if there are more bytes to read, the other 7 bits are used to encode the value.

In this implementation, the MSB is set to 1 if this byte is the last one.

E.g: 10000001 is value 1, 00000001 10000001 is 128 (decimal). Note that the value is stored little-endian, so in this example 10000001 00000001.

Author:
Bart.Hanssens
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    decode(byte[] bytes, int len)
    Decode a series of encoded bytes, with a maximum of 8 bytes
    static long
    Decode a maximum of 8 bytes from the input stream.
    static long
    decodeFrom(byte[] b, int start)
    Decode a maximum of 8 bytes from a byte array.
    static int
    encodedLength(long value)
    Calculate the number of bytes needed for encoding a value
    static boolean
    hasNext(byte b)
    Checks if the most significant bit is set.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • VByte

      public VByte()
  • Method Details

    • hasNext

      public static boolean hasNext(byte b)
      Checks if the most significant bit is set. If this bit is zero, then the next byte must also be read to decode the number.
      Parameters:
      b -
      Returns:
      true if there is a next byte
    • decode

      public static long decode(byte[] bytes, int len)
      Decode a series of encoded bytes, with a maximum of 8 bytes
      Parameters:
      bytes - byte array
      len - number of bytes to decode
      Returns:
      long value
    • decode

      public static long decode(InputStream is) throws IOException
      Decode a maximum of 8 bytes from the input stream.
      Parameters:
      is - input stream
      Returns:
      decode value
      Throws:
      IOException
    • decodeFrom

      public static long decodeFrom(byte[] b, int start) throws IOException
      Decode a maximum of 8 bytes from a byte array.
      Parameters:
      b - byte array
      start - starting position
      Returns:
      decode value
      Throws:
      IOException
    • encodedLength

      public static int encodedLength(long value)
      Calculate the number of bytes needed for encoding a value
      Parameters:
      value - numeric value
      Returns:
      number of bytes