【发布时间】:2012-03-19 12:39:45
【问题描述】:
我正在尝试解码我收到的字符串。 它在这里使用 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);
}
}
这段代码基本上是从 Java API 复制/粘贴的。 我也尝试过使用新的 Inflater(true);即nowrap
“注意:使用 'nowrap' 选项时,还需要提供一个额外的“虚拟”字节作为输入。这是 ZLIB 本机库要求的,以支持某些优化。”
那么这个虚拟字节应该添加到哪里呢? "byte[] decodedByteArray" 的开头还是结尾?
那么有什么想法可以解决这个问题吗?我是否只需要添加虚拟字节,是否需要使用其他方法等?
好吧,我想就是这样,感谢所有帮助!
问候
约翰
【问题讨论】: