标题: java解压缩出现异常:Unexpected end of ZLIB input stream [打印本页] 作者: adamjy 时间: 2014-4-21 19:52 标题: java解压缩出现异常:Unexpected end of ZLIB input stream 本帖最后由 adamjy 于 2014-4-22 12:40 编辑
通过java原生API将字符串进行压缩和解压缩,报异常了(Unexpected end of ZLIB input stream)。
在解压缩函数的gunzip.read(buffer)出了问题,跟踪进去看,异常由InflaterInputStream类的fill函数抛出。
InflaterInputStream类的fill()方法代码如下,
protected void fill() throws IOException {
ensureOpen();
len = in.read(buf, 0, buf.length);
if (len == -1) {
throw new EOFException("Unexpected end of ZLIB input stream");
}
inf.setInput(buf, 0, len);
}
复制代码
压缩解压缩代码如下,
public static String GetDeCompress(String src)
{
if (src == null || src.isEmpty()) {
return src;
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPInputStream gunzip = null;
String des = null;
try {
ByteArrayInputStream in = new ByteArrayInputStream(