Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Commit d6759a6

Browse files
committed
Add an example of LZ4FrameOutputStream and LZ4FrameOutputStream (#139)
1 parent 4bb85eb commit d6759a6

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Have a look at LZ4Factory for more information.
4343
especially if CPU endianness differs, but the compressed streams can be
4444
safely decompressed by any decompressor implementation on any platform.
4545

46-
## Example
46+
## Examples
4747

4848
```java
4949
LZ4Factory factory = LZ4Factory.fastestInstance();
@@ -71,6 +71,20 @@ int decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLeng
7171
// decompressedLength == decompressedLength2
7272
```
7373

74+
```java
75+
byte[] data = "12345345234572".getBytes("UTF-8");
76+
final int decompressedLength = data.length;
77+
78+
LZ4FrameOutputStream outStream = new LZ4FrameOutputStream(new FileOutputStream(new File("test.lz4")));
79+
outStream.write(data);
80+
outStream.close();
81+
82+
byte[] restored = new byte[decompressedLength];
83+
LZ4FrameInputStream inStream = new LZ4FrameInputStream(new FileInputStream(new File("test.lz4")));
84+
inStream.read(restored);
85+
inStream.close();
86+
```
87+
7488
# xxhash Java
7589

7690
xxhash hashing for Java, based on Yann Collet's work available at https://github.com/Cyan4973/xxHash (old version

0 commit comments

Comments
 (0)