summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@verizonmedia.com>2021-01-19 13:55:33 +0100
committerBjørn Christian Seime <bjorncs@verizonmedia.com>2021-01-19 13:55:33 +0100
commit095ba218f5dd1b57ef606c02393d43ae2e6e3c3d (patch)
treea4f0b15c64d9a1a93dc400a1cb0bf1b88e19abeb /vespajlib
parent2d700964107f60381de9091e724fcc316f36f4d7 (diff)
Extend ZstdCompressor with more low-level API methods
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/com/yahoo/compress/ZstdCompressor.java24
1 files changed, 20 insertions, 4 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/compress/ZstdCompressor.java b/vespajlib/src/main/java/com/yahoo/compress/ZstdCompressor.java
index 58a01df5b09..5d15b102ad6 100644
--- a/vespajlib/src/main/java/com/yahoo/compress/ZstdCompressor.java
+++ b/vespajlib/src/main/java/com/yahoo/compress/ZstdCompressor.java
@@ -15,16 +15,32 @@ public class ZstdCompressor {
private static final io.airlift.compress.zstd.ZstdDecompressor decompressor = new io.airlift.compress.zstd.ZstdDecompressor();
public byte[] compress(byte[] input, int inputOffset, int inputLength) {
- int maxCompressedLength = compressor.maxCompressedLength(inputLength);
+ int maxCompressedLength = getMaxCompressedLength(inputLength);
byte[] output = new byte[maxCompressedLength];
- int compressedLength = compressor.compress(input, inputOffset, inputLength, output, 0, maxCompressedLength);
+ int compressedLength = compress(input, inputOffset, inputLength, output, 0, maxCompressedLength);
return Arrays.copyOf(output, compressedLength);
}
+ public int compress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) {
+ return compressor.compress(input, inputOffset, inputLength, output, outputOffset, maxOutputLength);
+ }
+
public byte[] decompress(byte[] input, int inputOffset, int inputLength) {
- int decompressedLength = (int) io.airlift.compress.zstd.ZstdDecompressor.getDecompressedSize(input, inputOffset, inputLength);
+ int decompressedLength = getDecompressedLength(input, inputOffset, inputLength);
byte[] output = new byte[decompressedLength];
- decompressor.decompress(input, inputOffset, inputLength, output, 0, decompressedLength);
+ decompress(input, inputOffset, inputLength, output, 0, decompressedLength);
return output;
}
+
+ public int decompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) {
+ return decompressor.decompress(input, inputOffset, inputLength, output, outputOffset, maxOutputLength);
+ }
+
+ public static int getMaxCompressedLength(int uncompressedLength) {
+ return compressor.maxCompressedLength(uncompressedLength);
+ }
+
+ public static int getDecompressedLength(byte[] input, int inputOffset, int inputLength) {
+ return (int) io.airlift.compress.zstd.ZstdDecompressor.getDecompressedSize(input, inputOffset, inputLength);
+ }
}