Package org.h2.tools

# Class CompressTool

java.lang.Object
org.h2.tools.CompressTool

public class CompressTool extends Object
A tool to losslessly compress data, and expand the compressed data again.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`BZIP2_INPUT_CLASS_NAME`
`static final String`
`BZIP2_OUTPUT_CLASS_NAME`
`static final String`
`KANZI_INPUT_CLASS_NAME`
`static final String`
`KANZI_OUTPUT_CLASS_NAME`

## Method Summary

Modifier and Type
Method
Description
`byte[]`
`compress(byte[] in, String algorithm)`
Compressed the data using the specified algorithm.
`static InputStream`
`createBZip2InputStream(InputStream inputStream)`
Creates a BZip2 decompressing input stream using reflection.
`static OutputStream`
`createBZip2OutputStream(OutputStream baseOutputStream)`
Creates a BZip2 compressing output stream using reflection.
`static InputStream`
`createKanziInputStream(InputStream inputStream, ExecutorService executor)`
Creates a Kanzi decompressing input stream using reflection.
`static OutputStream`
`createKanziOutputStream(OutputStream baseOutputStream, ExecutorService executor)`
Creates a Kanzi compressing output stream using reflection.
`byte[]`
`expand(byte[] in)`
Expands the compressed data.
`static void`
`expand(byte[] in, byte[] out, int outPos)`
INTERNAL
`static CompressTool`
`getInstance()`
Get a new instance.
`static int`
`getVariableIntLength(int x)`
Get a variable size integer length using Rice coding.
`static int`
`readVariableInt(byte[] buff, int pos)`
Read a variable size integer using Rice coding.
`static InputStream`
`wrapInputStream(InputStream in, String compressionAlgorithm, String entryName)`
INTERNAL
`static InputStream`
`wrapInputStream(InputStream in, String compressionAlgorithm, String entryName, ExecutorService executor)`
INTERNAL
`static OutputStream`
`wrapOutputStream(OutputStream out, String compressionAlgorithm, String entryName)`
INTERNAL
`static OutputStream`
`wrapOutputStream(OutputStream out, String compressionAlgorithm, String entryName, ExecutorService executor)`
INTERNAL
`static int`
`writeVariableInt(byte[] buff, int pos, int x)`
Write a variable size integer using Rice coding.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### KANZI_OUTPUT_CLASS_NAME

public static final String KANZI_OUTPUT_CLASS_NAME

See Also:
  - Constant Field Values

### KANZI_INPUT_CLASS_NAME

public static final String KANZI_INPUT_CLASS_NAME

See Also:
  - Constant Field Values

### BZIP2_OUTPUT_CLASS_NAME

public static final String BZIP2_OUTPUT_CLASS_NAME

See Also:
  - Constant Field Values

### BZIP2_INPUT_CLASS_NAME

public static final String BZIP2_INPUT_CLASS_NAME

See Also:
  - Constant Field Values

## Method Details

### createBZip2OutputStream

public static OutputStream createBZip2OutputStream(OutputStream baseOutputStream)
Creates a BZip2 compressing output stream using reflection.

### createBZip2InputStream

public static InputStream createBZip2InputStream(InputStream inputStream)
Creates a BZip2 decompressing input stream using reflection.

### createKanziOutputStream

public static OutputStream createKanziOutputStream(OutputStream baseOutputStream, ExecutorService executor)
Creates a Kanzi compressing output stream using reflection.

### createKanziInputStream

public static InputStream createKanziInputStream(InputStream inputStream, ExecutorService executor)
Creates a Kanzi decompressing input stream using reflection.

### getInstance

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:
  a new instance

### compress

public byte[] compress(byte[] in, String algorithm)
Compressed the data using the specified algorithm. If no algorithm is supplied, LZF is used

Parameters:
  `in` - the byte array with the original data
  `algorithm` - the algorithm (LZF, DEFLATE)
Returns:
  the compressed data

### expand

public byte[] expand(byte[] in)
Expands the compressed data.

Parameters:
  `in` - the byte array with the compressed data
Returns:
  the uncompressed data

### expand

public static void expand(byte[] in, byte[] out, int outPos)
INTERNAL

Parameters:
  `in` - compressed data
  `out` - uncompressed result
  `outPos` - the offset at the output array

### readVariableInt

public static int readVariableInt(byte[] buff, int pos)
Read a variable size integer using Rice coding.

Parameters:
  `buff` - the buffer
  `pos` - the position
Returns:
  the integer

### writeVariableInt

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` - the buffer
  `pos` - the position
  `x` - the value
Returns:
  the number of bytes written (0-5)

### getVariableIntLength

public static int getVariableIntLength(int x)
Get a variable size integer length using Rice coding. Negative values need 5 bytes.

Parameters:
  `x` - the value
Returns:
  the number of bytes needed (0-5)

### wrapOutputStream

public static OutputStream wrapOutputStream(OutputStream out, String compressionAlgorithm, String entryName)
INTERNAL

Parameters:
  `out` - stream
  `compressionAlgorithm` - to be used
  `entryName` - in a zip file
Returns:
  compressed stream

### wrapOutputStream

public static OutputStream wrapOutputStream(OutputStream out, String compressionAlgorithm, String entryName, ExecutorService executor)
INTERNAL

Parameters:
  `out` - stream
  `compressionAlgorithm` - to be used
  `entryName` - in a zip file
  `executor` - for supervising the parallel execution (KANZI only)
Returns:
  compressed stream

### wrapInputStream

public static InputStream wrapInputStream(InputStream in, String compressionAlgorithm, String entryName)
INTERNAL

Parameters:
  `in` - stream
  `compressionAlgorithm` - to be used
  `entryName` - in a zip file
Returns:
  in stream or null if there is no such entry

### wrapInputStream

public static InputStream wrapInputStream(InputStream in, String compressionAlgorithm, String entryName, ExecutorService executor)
INTERNAL

Parameters:
  `in` - stream
  `compressionAlgorithm` - to be used
  `entryName` - in a zip file
  `executor` - for supervising the parallel execution (KANZI only)
Returns:
  in stream or null if there is no such entry