org.exist.util
Class VariableByteCoding

java.lang.Object
  extended byorg.exist.util.VariableByteCoding

public class VariableByteCoding
extends java.lang.Object

This class encodes integer values using variable-byte coding. In variable-byte coding, the value is split into a sequence of 7-bit chunks. Bit 8 is used to indicate if more bytes follow. If bit 8 is 0, all bytes have been read. Variable-byte coding usually achieves good compression ratios for a sequence of random integer values. Compression ratio is bad for very small and very large values.

Author:
Wolfgang Meier

Constructor Summary
VariableByteCoding()
           
 
Method Summary
static void copyTo(java.io.InputStream in, ByteArray out)
           
static void copyTo(java.io.InputStream in, ByteArray out, int count)
           
static long decode(byte[] d, int offset)
          Decode a variable-byte encoded sequence
static long decode(java.io.InputStream is)
          Decode a variable-byte encoded sequence
static long decodeFixed(java.io.InputStream is)
           
static void encode(ByteArray buf, long l)
          Encode a long integer to a variable-byte encoded sequence of bytes.
static byte[] encode(long l)
          Encode a long integer to a variable-byte encoded sequence of bytes.
static void encode(long l, byte[] data, int offset)
          Encode a long integer to a variable-byte encoded sequence of bytes.
static void encodeFixed(ByteArray buf, long l)
           
static int getSize(long l)
          Get the size of the variable-byte encoded sequence for a given long.
static void skipNext(java.io.InputStream is)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VariableByteCoding

public VariableByteCoding()
Method Detail

decode

public static final long decode(byte[] d,
                                int offset)
Decode a variable-byte encoded sequence

Parameters:
d - the variable-byte encoded sequence of bytes
offset - the offset at which decoding should start
Returns:
the decoded value

decode

public static final long decode(java.io.InputStream is)
                         throws java.io.IOException
Decode a variable-byte encoded sequence

Parameters:
is - ByteArrayInputStream to read the variable-byte encoded data from
Returns:
the decoded value
Throws:
java.io.IOException

skipNext

public static final void skipNext(java.io.InputStream is)
                           throws java.io.IOException
Throws:
java.io.IOException

copyTo

public static final void copyTo(java.io.InputStream in,
                                ByteArray out)
                         throws java.io.IOException
Throws:
java.io.IOException

copyTo

public static final void copyTo(java.io.InputStream in,
                                ByteArray out,
                                int count)
                         throws java.io.IOException
Throws:
java.io.IOException

encode

public static final byte[] encode(long l)
Encode a long integer to a variable-byte encoded sequence of bytes.

Parameters:
l - The long integer value to encode
Returns:
The coded byte sequence

encode

public static final void encode(long l,
                                byte[] data,
                                int offset)
Encode a long integer to a variable-byte encoded sequence of bytes.

Parameters:
l - Description of the Parameter
data - Description of the Parameter
offset - Description of the Parameter

encode

public static final void encode(ByteArray buf,
                                long l)
Encode a long integer to a variable-byte encoded sequence of bytes. Write output to a FastByteBuffer.

Parameters:
buf - Description of the Parameter
l - Description of the Parameter

encodeFixed

public static final void encodeFixed(ByteArray buf,
                                     long l)

decodeFixed

public static final long decodeFixed(java.io.InputStream is)
                              throws java.io.IOException
Throws:
java.io.IOException

getSize

public static final int getSize(long l)
Get the size of the variable-byte encoded sequence for a given long.

Parameters:
l - Description of the Parameter
Returns:
The size value


Copyright (C) Wolfgang Meier. All rights reserved.