Top Description Fields Constructors Methods
org.apache.derby.iapi.services.io

public abstract Class CompressedNumber

extends Object
Class Inheritance
Imports
org.apache.derby.shared.common.sanity.SanityManager, java.io.*

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

Modifier and TypeField and Description
public static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static final int

Returns:

the deserialized int value
readInt
(DataInput
Whence to read an int
in
)

Read an integer previously written by writeInt().

public static final int

Returns:

the deserialized int value
readInt
(InputStream
Whence to read an int
in
)

Read an integer previously written by writeInt().

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

public static final long

Returns:

the deserialized long value
readLong
(DataInput
Whence to read a long value
in
)

Read a long previously written by writeLong().

public static final long

Returns:

the deserialized long value
readLong
(InputStream
Whence to read the long value
in
)

Read a long previously written by writeLong().

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

public static final int

Returns:

the number of bytes which would be written
sizeInt
(int
The int value to be serialized
value
)

Return the number of bytes that would be written by a writeInt call

public static final int
sizeLong(long value)

public static final int

Returns:

the number of bytes written
writeInt
(DataOutput
Where to serialize the int value
out
,
int
The value to serialize
value
)

Write a compressed integer only supporting signed values.

public static final int

Returns:

the number of bytes written
writeInt
(OutputStream
Where to serialize the int value
out
,
int
The int value to serialize
value
)

Write a compressed integer directly to an OutputStream.

public static final int

Returns:

the number of bytes written
writeLong
(DataOutput
Where to write the long value
out
,
long
The long value to write
value
)

Write a compressed long only supporting signed values.

public static final int

Returns:

the number of bytes written
writeLong
(OutputStream
Where to write the long
out
,
long
The long to write
value
)

Write a compressed integer only supporting signed values.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MAX_COMPRESSED_INT_ONE_BYTEback to summary
public static final int MAX_COMPRESSED_INT_ONE_BYTE
MAX_COMPRESSED_INT_TWO_BYTESback to summary
public static final int MAX_COMPRESSED_INT_TWO_BYTES
MAX_INT_STORED_SIZEback to summary
public static final int MAX_INT_STORED_SIZE
MAX_LONG_STORED_SIZEback to summary
public static final int MAX_LONG_STORED_SIZE

Constructor Detail

CompressedNumberback to summary
public CompressedNumber()

Method Detail

readIntback to summary
public static final int readInt(DataInput in) throws IOException

Read an integer previously written by writeInt().

Parameters
in:DataInput

Whence to read an int

Returns:int

the deserialized int value

Exceptions
IOException:
an exception was thrown by a method on in.
readIntback to summary
public static final int readInt(InputStream in) throws IOException

Read an integer previously written by writeInt().

Parameters
in:InputStream

Whence to read an int

Returns:int

the deserialized int value

Exceptions
IOException:
an exception was thrown by a method on in.
readIntback to summary
public static final int readInt(byte[] data, int offset)
readLongback to summary
public static final long readLong(DataInput in) throws IOException

Read a long previously written by writeLong().

Parameters
in:DataInput

Whence to read a long value

Returns:long

the deserialized long value

Exceptions
IOException:
an exception was thrown by a method on in.
readLongback to summary
public static final long readLong(InputStream in) throws IOException

Read a long previously written by writeLong().

Parameters
in:InputStream

Whence to read the long value

Returns:long

the deserialized long value

Exceptions
IOException:
an exception was thrown by a method on in.
readLongback to summary
public static final long readLong(byte[] data, int offset)
sizeIntback to summary
public static final int sizeInt(int value)

Return the number of bytes that would be written by a writeInt call

Parameters
value:int

The int value to be serialized

Returns:int

the number of bytes which would be written

sizeLongback to summary
public static final int sizeLong(long value)
writeIntback to summary
public static final int writeInt(DataOutput out, int value) throws 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
		
Parameters
out:DataOutput

Where to serialize the int value

value:int

The value to serialize

Returns:int

the number of bytes written

Exceptions
IOException:
value is negative or an exception was thrown by a method on out.
writeIntback to summary
public static final int writeInt(OutputStream out, int value) throws IOException

Write a compressed integer directly to an OutputStream.

Parameters
out:OutputStream

Where to serialize the int value

value:int

The int value to serialize

Returns:int

the number of bytes written

Exceptions
IOException:
an exception was thrown by a method on in.
writeLongback to summary
public static final int writeLong(DataOutput out, long value) throws 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
		
Parameters
out:DataOutput

Where to write the long value

value:long

The long value to write

Returns:int

the number of bytes written

Exceptions
IOException:
value is negative or an exception was thrown by a method on out.
writeLongback to summary
public static final int writeLong(OutputStream out, long value) throws IOException

Write a compressed integer only supporting signed values.

Parameters
out:OutputStream

Where to write the long

value:long

The long to write

Returns:int

the number of bytes written

Exceptions
IOException:
value is negative or an exception was thrown by a method on out.