org.apache.derby.iapi.services.io
Class CompressedNumber

java.lang.Object
  extended byorg.apache.derby.iapi.services.io.CompressedNumber

public abstract class CompressedNumber
extends java.lang.Object

Static methods to write and read compressed forms of numbers to DataOut and DataIn interfaces. Format written is platform independent like the Data* interfaces and must remain fixed once a product is shipped. If a different format is required then write a new set of methods, e.g. writeInt2. The formats defined by stored format identifiers are implicitly dependent on these formats not changing.


Field Summary
private static ArrayInputStream ais
           
private static ArrayOutputStream aos
           
private static byte[] holder
           
private static java.io.DataInput in
           
private static java.io.InputStream in_stream
           
static int MAX_COMPRESSED_INT_ONE_BYTE
           
static int MAX_COMPRESSED_INT_TWO_BYTES
           
static int MAX_INT_STORED_SIZE
           
static int MAX_LONG_STORED_SIZE
           
private static java.io.DataOutput out
           
 
Constructor Summary
CompressedNumber()
           
 
Method Summary
private static short checkInt(int i, short oldLength)
           
private static short checkLong(long i, short oldLength)
           
static void main(java.lang.String[] args)
           
static int readInt(byte[] data, int offset)
           
static int readInt(java.io.DataInput in)
          Read an integer previously written by writeInt().
static int readInt(java.io.InputStream in)
          Read an integer previously written by writeInt().
static int readIntAndReturnIntPlusOverhead(byte[] data, int offset)
          Return the compressed Int value + stored size of the length + 1 Given offset in array to beginning of compressed int, return the value of the compressed int + the number of bytes used to store the length.
static long readLong(byte[] data, int offset)
           
static long readLong(java.io.DataInput in)
          Read a long previously written by writeLong().
static long readLong(java.io.InputStream in)
          Read a long previously written by writeLong().
static int sizeInt(int value)
          Return the number of bytes that would be written by a writeInt call
static int sizeLong(long value)
           
static int skipInt(java.io.DataInput in)
          Skip an integer previously written by writeInt().
static int skipInt(java.io.InputStream in)
          Skip an integer previously written by writeInt().
static int skipLong(java.io.DataInput in)
          Skip a long previously written by writeLong().
static int skipLong(java.io.InputStream in)
          Skip a long previously written by writeLong().
static int writeInt(java.io.DataOutput out, int value)
          Write a compressed integer only supporting signed values.
static int writeInt(java.io.OutputStream out, int value)
          Write a compressed integer directly to an OutputStream.
static int writeLong(java.io.DataOutput out, long value)
          Write a compressed long only supporting signed values.
static int writeLong(java.io.OutputStream out, long value)
          Write a compressed integer only supporting signed values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_INT_STORED_SIZE

public static final int MAX_INT_STORED_SIZE
See Also:
Constant Field Values

MAX_LONG_STORED_SIZE

public static final int MAX_LONG_STORED_SIZE
See Also:
Constant Field Values

MAX_COMPRESSED_INT_ONE_BYTE

public static final int MAX_COMPRESSED_INT_ONE_BYTE
See Also:
Constant Field Values

MAX_COMPRESSED_INT_TWO_BYTES

public static final int MAX_COMPRESSED_INT_TWO_BYTES
See Also:
Constant Field Values

holder

private static byte[] holder

aos

private static ArrayOutputStream aos

out

private static java.io.DataOutput out

ais

private static ArrayInputStream ais

in

private static java.io.DataInput in

in_stream

private static java.io.InputStream in_stream
Constructor Detail

CompressedNumber

public CompressedNumber()
Method Detail

writeInt

public static final int writeInt(java.io.DataOutput out,
                                 int value)
                          throws java.io.IOException
Write a compressed integer only supporting signed values. Formats are (with x representing value bits):
                1 Byte - 00xxxxxx                              Represents the value <= 63 (0x3f)
                2 Byte - 01xxxxxx xxxxxxxx                     Represents the value > 63 && <= 16383 (0x3fff)
                4 byte - 1xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Represents the value > 16383 && <= MAX_INT
                

Throws:
java.io.IOException - value is negative or an exception was thrown by a method on out.

writeInt

public static final int writeInt(java.io.OutputStream out,
                                 int value)
                          throws java.io.IOException
Write a compressed integer directly to an OutputStream.

Throws:
java.io.IOException - an exception was thrown by a method on in.

readInt

public static final int readInt(java.io.DataInput in)
                         throws java.io.IOException
Read an integer previously written by writeInt().

Throws:
java.io.IOException - an exception was thrown by a method on in.

readInt

public static final int readInt(java.io.InputStream in)
                         throws java.io.IOException
Read an integer previously written by writeInt().

Throws:
java.io.IOException - an exception was thrown by a method on in.

readInt

public static final int readInt(byte[] data,
                                int offset)

readIntAndReturnIntPlusOverhead

public static final int readIntAndReturnIntPlusOverhead(byte[] data,
                                                        int offset)
Return the compressed Int value + stored size of the length + 1

Given offset in array to beginning of compressed int, return the value of the compressed int + the number of bytes used to store the length.

So 1 byte lengths will return: length + 1 + 1 So 2 byte lengths will return: length + 2 + 1 So 4 byte lengths will return: length + 4 + 1

Note that this routine will not work for lengths MAX_INT - (MAX_INT - 5).

This routine is currently used by the StorePage code to skip fields as efficiently as possible. Since the page size is less than (MAX_INT - 5) it is all right to use this routine.

Parameters:
data - byte array containing the field.
offset - offset to beginning of field, ie. data[offset] contains 1st byte of the compressed int.
Returns:
compressed int value + length used to store the length.

skipInt

public static final int skipInt(java.io.DataInput in)
                         throws java.io.IOException
Skip an integer previously written by writeInt().

Throws:
java.io.IOException - an exception was thrown by a method on in.

skipInt

public static final int skipInt(java.io.InputStream in)
                         throws java.io.IOException
Skip an integer previously written by writeInt().

Throws:
java.io.IOException - an exception was thrown by a method on in.

sizeInt

public static final int sizeInt(int value)
Return the number of bytes that would be written by a writeInt call


writeLong

public static final int writeLong(java.io.DataOutput out,
                                  long value)
                           throws java.io.IOException
Write a compressed long only supporting signed values. Formats are (with x representing value bits):
                2 byte - 00xxxxxx xxxxxxxx                     Represents the value <= 16383 (0x3fff)
                4 byte - 01xxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Represents the value > 16383  && <= 0x3fffffff
                8 byte - 1xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Represents the value > 0x3fffffff && <= MAX_LONG
                

Throws:
java.io.IOException - value is negative or an exception was thrown by a method on out.

writeLong

public static final int writeLong(java.io.OutputStream out,
                                  long value)
                           throws java.io.IOException
Write a compressed integer only supporting signed values.

Throws:
java.io.IOException - value is negative or an exception was thrown by a method on out.

readLong

public static final long readLong(java.io.DataInput in)
                           throws java.io.IOException
Read a long previously written by writeLong().

Throws:
java.io.IOException - an exception was thrown by a method on in.

readLong

public static final long readLong(java.io.InputStream in)
                           throws java.io.IOException
Read a long previously written by writeLong().

Throws:
java.io.IOException - an exception was thrown by a method on in.

readLong

public static final long readLong(byte[] data,
                                  int offset)

skipLong

public static final int skipLong(java.io.DataInput in)
                          throws java.io.IOException
Skip a long previously written by writeLong().

Throws:
java.io.IOException - an exception was thrown by a method on in.

skipLong

public static final int skipLong(java.io.InputStream in)
                          throws java.io.IOException
Skip a long previously written by writeLong().

Throws:
java.io.IOException - an exception was thrown by a method on in.

sizeLong

public static final int sizeLong(long value)

checkInt

private static short checkInt(int i,
                              short oldLength)
                       throws java.io.IOException
Throws:
java.io.IOException

checkLong

private static short checkLong(long i,
                               short oldLength)
                        throws java.io.IOException
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Throws:
java.io.IOException


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.