Top Description Fields Constructors Methods
org.h2.tools

public Class CompressTool

extends Object
Class Inheritance
Static Imports
org.h2.util.Bits.INT_VH_BE

A tool to losslessly compress data, and expand the compressed data again.

Field Summary

Modifier and TypeField and Description
private byte[]
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

the compressed data
compress
(byte[]
the byte array with the original data
in
,
String
the algorithm (LZF, DEFLATE)
algorithm
)

Compressed the data using the specified algorithm.

private static int
compress(byte[] in, int len, Compressor compress, byte[] out)

public byte[]

Returns:

the uncompressed data
expand
(byte[]
the byte array with the compressed data
in
)

Expands the compressed data.

public static void
expand(byte[]
compressed data
in
,
byte[]
uncompressed result
out
,
int
the offset at the output array
outPos
)

INTERNAL

private byte[]
getBuffer(int min)

private static int

Returns:

index of the specified algorithm
getCompressAlgorithm
(String
to translate into index
algorithm
)

INTERNAL

private static Compressor
getCompressor(String algorithm)

private static Compressor
getCompressor(int algorithm)

public static CompressTool

Returns:

a new instance
getInstance
()

Get a new instance.

public static int

Returns:

the number of bytes needed (0-5)
getVariableIntLength
(int
the value
x
)

Get a variable size integer length using Rice coding.

public static int

Returns:

the integer
readVariableInt
(byte[]
the buffer
buff
,
int
the position
pos
)

Read a variable size integer using Rice coding.

public static InputStream

Returns:

in stream or null if there is no such entry
wrapInputStream
(InputStream
stream
in
,
String
to be used
compressionAlgorithm
,
String
in a zip file
entryName
)

INTERNAL

public static OutputStream

Returns:

compressed stream
wrapOutputStream
(OutputStream
stream
out
,
String
to be used
compressionAlgorithm
,
String
in a zip file
entryName
)

INTERNAL

public static int

Returns:

the number of bytes written (0-5)
writeVariableInt
(byte[]
the buffer
buff
,
int
the position
pos
,
int
the value
x
)

Write a variable size integer using Rice coding.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferback to summary
private byte[] buffer
MAX_BUFFER_SIZEback to summary
private static final int MAX_BUFFER_SIZE

Constructor Detail

CompressToolback to summary
private CompressTool()

Method Detail

compressback to summary
public byte[] compress(byte[] in, String algorithm)

Compressed the data using the specified algorithm. If no algorithm is supplied, LZF is used

Parameters
in:byte[]

the byte array with the original data

algorithm:String

the algorithm (LZF, DEFLATE)

Returns:byte[]

the compressed data

compressback to summary
private static int compress(byte[] in, int len, Compressor compress, byte[] out)
expandback to summary
public byte[] expand(byte[] in)

Expands the compressed data.

Parameters
in:byte[]

the byte array with the compressed data

Returns:byte[]

the uncompressed data

expandback to summary
public static void expand(byte[] in, byte[] out, int outPos)

INTERNAL

Parameters
in:byte[]

compressed data

out:byte[]

uncompressed result

outPos:int

the offset at the output array

getBufferback to summary
private byte[] getBuffer(int min)
getCompressAlgorithmback to summary
private static int getCompressAlgorithm(String algorithm)

INTERNAL

Parameters
algorithm:String

to translate into index

Returns:int

index of the specified algorithm

getCompressorback to summary
private static Compressor getCompressor(String algorithm)
getCompressorback to summary
private static Compressor getCompressor(int algorithm)
getInstanceback to summary
public static CompressTool getInstance()

Get a new instance. Each instance uses a separate buffer, so multiple instances can be used concurrently. However each instance alone is not multithreading safe.

Returns:CompressTool

a new instance

getVariableIntLengthback to summary
public static int getVariableIntLength(int x)

Get a variable size integer length using Rice coding. Negative values need 5 bytes.

Parameters
x:int

the value

Returns:int

the number of bytes needed (0-5)

readVariableIntback to summary
public static int readVariableInt(byte[] buff, int pos)

Read a variable size integer using Rice coding.

Parameters
buff:byte[]

the buffer

pos:int

the position

Returns:int

the integer

wrapInputStreamback to summary
public static InputStream wrapInputStream(InputStream in, String compressionAlgorithm, String entryName)

INTERNAL

Parameters
in:InputStream

stream

compressionAlgorithm:String

to be used

entryName:String

in a zip file

Returns:InputStream

in stream or null if there is no such entry

wrapOutputStreamback to summary
public static OutputStream wrapOutputStream(OutputStream out, String compressionAlgorithm, String entryName)

INTERNAL

Parameters
out:OutputStream

stream

compressionAlgorithm:String

to be used

entryName:String

in a zip file

Returns:OutputStream

compressed stream

writeVariableIntback to summary
public static int writeVariableInt(byte[] buff, int pos, int x)

Write a variable size integer using Rice coding. Negative values need 5 bytes.

Parameters
buff:byte[]

the buffer

pos:int

the position

x:int

the value

Returns:int

the number of bytes written (0-5)