]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.lz4/src/net/jpountz/lz4/package.html
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.lz4 / src / net / jpountz / lz4 / package.html
1 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
2 <!--
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
6
7        http://www.apache.org/licenses/LICENSE-2.0
8
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.
14 -->
15 <html>
16 <head>
17    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
18 </head>
19 <body>
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>
24
25
26 <p>Sample usage:</p>
27
28 <pre class="prettyprint">
29     LZ4Factory factory = LZ4Factory.fastestInstance();
30
31     byte[] data = "12345345234572".getBytes("UTF-8");
32     final int decompressedLength = data.length;
33
34     // compress data
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);
39
40     // decompress data
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
46
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
52 </pre>
53
54 </body>
55 </html>