问题描述
我一直在努力使用Luben库(v1.4.0-1)将常规字符串压缩为ZSTD格式.我执行以下操作:
I have been struggling to compress a regular string to ZSTD format using the Luben library (v1.4.0-1). I do the following:
byte[] zstdBytes = Zstd.compress(payload.getBytes(StandardCharsets.UTF_8));
ZstdInputStream zstdInputStream= new ZstdInputStream(new ByteArrayInputStream(zstdBytes));
但是,在读取zstdInputStream时,出现以下错误:
However while reading the zstdInputStream I get the following error:
java.io.IOException: Decompression error: Unknown frame descriptor
at com.github.luben.zstd.ZstdInputStream.readInternal(ZstdInputStream.java:142)
at com.github.luben.zstd.ZstdInputStream.read(ZstdInputStream.java:102)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:161)
at java.io.BufferedReader.read(BufferedReader.java:182)
我对zstdInputStream代码的阅读如下:
My reading of the zstdInputStream code is as follows:
try (ZstdInputStream zis = new ZstdInputStream(new UncloseableStream(payload))) {
try (Reader reader = new BufferedReader(new InputStreamReader(zis))) {
int data = reader.read();
while (data != -1) {
System.out.print((char) data);
data = reader.read();
}
}
}
我的有效载荷如下:{客户":"CA101",源":实时",操作":添加",类型":"BC",容器":"c_789",令牌":"BC_mc-1CA101_20101206_0",优先级":5,"jsonPayload":; {"guid":"89df67","id":"id789","llevel":"INFO","ldate":"20180526","lthread":索引"-789","lmethod":"GET","afield":"aaa","bfield":"bbb","cfield":"ccc","dfield":"; ddd","efield":"eee","data":"Hello world" fancy","hostname":"uk-sx1-1","instanceid":"swg"-89",服务":索引",网格":"UK",原点":"0",时间":1508,偏移":7845}";}
My payload is as follows:{"customer":"CA101","source": "live","operation":"add","type": "BC","container": "c_789","token": "BC_mc- l_CA101_20101206_0","priority": 5,"jsonPayload": "{"guid":"89df67","id":"id789","llevel":"INFO","ldate":"20180526","lthread":"Indexing-789","lmethod":"GET","afield":"aaa","bfield":"bbb","cfield":"ccc","dfield":"ddd","efield":"eee","data":"Hello world "fancy","hostname":"uk-sx1-1","instanceid":"swg-89","service":"indexing","grid":"UK","origin":"0","time":1508,"loffset":7845"}"}
推荐答案
所以我发现了为什么它不起作用.我不应该使用以下行:
So I found why it was not working. I shouldn't have used the following line:
ZstdInputStream zstdInputStream= new ZstdInputStream(new ByteArrayInputStream(zstdBytes));
基本上可行:
byte[] zstdBytes = Zstd.compress(payload.getBytes(StandardCharsets.UTF_8));
InputStream inputStream = new ByteArrayInputStream(zstdBytes);
这篇关于使用luben的ZSTD字符串压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!