com.sun.sgs.impl.util
Class Int30

java.lang.Object
  extended by com.sun.sgs.impl.util.Int30

public final class Int30
extends Object

Provides utilities for reading and writing 30-bit integers in a compressed format that is smaller for smaller integers. Does not support negative integers or values above 2^30 - 1 or 1073741823.

The high order two bits of the first byte specify the number of additional bytes beyond the first byte that will be needed to store the entire integer. The bottom 6 bits of the first byte hold the highest order bits of the integer, with the following bytes holding the remaining bytes.

Values less than 2^6 are represented by just storing the value in a single byte, since the top two marking bits are zero:

Values less than 2^14 are represented in two bytes, with the top two bits of the first byte set to 01 binary:

Values less than 2^22 take three bytes, with 10 binary in the top bits, and less than 2^30 take four, with 11 binary in the top bits:


Field Summary
static int MAX_VALUE
          The maximum integer that can be encoded.
 
Method Summary
static int read(InputStream in)
          Reads a 30-bit integer from an input stream.
static void write(int n, OutputStream out)
          Writes a 30-bit integer to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_VALUE

public static final int MAX_VALUE
The maximum integer that can be encoded.

See Also:
Constant Field Values
Method Detail

write

public static void write(int n,
                         OutputStream out)
                  throws IOException
Writes a 30-bit integer to an output stream.

Parameters:
n - the integer
out - the output stream
Throws:
IllegalArgumentException - if n is less than 0 or greater than 1073741823
IOException - if an I/O error occurs

read

public static int read(InputStream in)
                throws IOException
Reads a 30-bit integer from an input stream.

Parameters:
in - the input stream
Returns:
the integer
Throws:
IOException - if an I/O error occurs

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved