blob: 101f5f424fbdc5e734f17ad6fbafe46f0329cd67 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config;
import com.yahoo.compress.CompressionType;
import com.yahoo.compress.Compressor;
import java.nio.ByteBuffer;
/**
* Wrapper for LZ4 compression that selects compression level based on properties.
*
* @author Ulf Lilleengen
*/
public class LZ4PayloadCompressor {
private static final Compressor compressor = new Compressor(CompressionType.LZ4, 0);
public byte[] compress(byte[] input) {
return compressor.compressUnconditionally(input);
}
public byte[] compress(ByteBuffer input) {
return compressor.compressUnconditionally(input);
}
public byte [] decompress(byte[] input, int uncompressedLen) {
return compressor.decompressUnconditionally(input, 0, uncompressedLen);
}
public byte [] decompress(ByteBuffer input, int uncompressedLen) {
ByteBuffer uncompressed = ByteBuffer.allocate(uncompressedLen);
compressor.decompressUnconditionally(input, uncompressed);
return uncompressed.array();
}
}
|