我正在尝试解码收到的字符串。它使用这里的 deflater 进行压缩: https: //github.com/dankogai/js-deflate 然后进行 base64 编码。
但是,当我使用 java inflater 时,我收到以下错误消息:未知的压缩方法。
import sun.misc.BASE64Decoder;
public void org() throws Exception{
BASE64Decoder decoder = new BASE64Decoder();
try {
String inputString = "84VWAVDY";
byte[] decodedByteArray = decoder.decodeBuffer(inputString);
// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(decodedByteArray);
byte[] result = new byte[100];
int resultLength = decompresser.inflate(result);
decompresser.end();
// Decode the bytes into a String
String outputString = new String(result, 0, resultLength);
System.out.println("OUTPUT:" + outputString);
} catch (Exception e){
System.out.println("Exception: " + e);
}
}
Run Code Online (Sandbox Code Playgroud)
该代码基本上是来自 Java API 的复制/粘贴。我也尝试过使用新的 Inflater(true); 即现在的包裹
“注意:使用‘nowrap’选项时,还需要提供额外的‘虚拟’字节作为输入。ZLIB 本机库需要这样做才能支持某些优化。”
那么这个虚拟字节应该添加到哪里呢?在“byte[]解码字节数组”的开头或结尾?
那么有什么想法可以解决这个问题吗?我是否只需要添加虚拟字节,是否需要使用其他方法等?
好吧,我想就是这样,感谢所有帮助!
问候
约翰
| 归档时间: |
|
| 查看次数: |
5037 次 |
| 最近记录: |