Package org.h2.tools
Class CompressTool
java.lang.Object
org.h2.tools.CompressTool
A tool to losslessly compress data, and expand the compressed data again.
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]Compressed the data using the specified algorithm.byte[]expand(byte[] in) Expands the compressed data.static voidexpand(byte[] in, byte[] out, int outPos) INTERNALstatic CompressToolGet a new instance.static intgetVariableIntLength(int x) Get a variable size integer length using Rice coding.static intreadVariableInt(byte[] buff, int pos) Read a variable size integer using Rice coding.static InputStreamwrapInputStream(InputStream in, String compressionAlgorithm, String entryName) INTERNALstatic OutputStreamwrapOutputStream(OutputStream out, String compressionAlgorithm, String entryName) INTERNALstatic intwriteVariableInt(byte[] buff, int pos, int x) Write a variable size integer using Rice coding.
-
Method Details
-
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
Compressed the data using the specified algorithm. If no algorithm is supplied, LZF is used- Parameters:
in- the byte array with the original dataalgorithm- 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 dataout- uncompressed resultoutPos- 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 bufferpos- 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 bufferpos- the positionx- 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- streamcompressionAlgorithm- to be usedentryName- in a zip file- Returns:
- compressed stream
-
wrapInputStream
public static InputStream wrapInputStream(InputStream in, String compressionAlgorithm, String entryName) INTERNAL- Parameters:
in- streamcompressionAlgorithm- to be usedentryName- in a zip file- Returns:
- in stream or null if there is no such entry
-