1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
17 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
20 <p>LZ4 compression. The entry point of the API is the
21 {@link net.jpountz.lz4.LZ4Factory} class, which gives access to
22 {@link net.jpountz.lz4.LZ4Compressor compressors} and
23 {@link net.jpountz.lz4.LZ4SafeDecompressor decompressors}.</p>
28 <pre class="prettyprint">
29 LZ4Factory factory = LZ4Factory.fastestInstance();
31 byte[] data = "12345345234572".getBytes("UTF-8");
32 final int decompressedLength = data.length;
35 LZ4Compressor compressor = factory.fastCompressor();
36 int maxCompressedLength = compressor.maxCompressedLength(decompressedLength);
37 byte[] compressed = new byte[maxCompressedLength];
38 int compressedLength = compressor.compress(data, 0, decompressedLength, compressed, 0, maxCompressedLength);
41 // - method 1: when the decompressed length is known
42 LZ4FastDecompressor decompressor = factory.fastDecompressor();
43 byte[] restored = new byte[decompressedLength];
44 int compressedLength2 = decompressor.decompress(compressed, 0, restored, 0, decompressedLength);
45 // compressedLength == compressedLength2
47 // - method 2: when the compressed length is known (a little slower)
48 // the destination buffer needs to be over-sized
49 LZ4SafeDecompressor decompressor2 = factory.safeDecompressor();
50 int decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLength, restored, 0);
51 // decompressedLength == decompressedLength2