java.util.zip.ZipException: invalid distance too far back while decompressing

拈花ヽ惹草 提交于 2019-11-27 06:48:06

问题


util.zip.ZipException: invalid distance too far back this exception when i am decompressing my data....it occurs in this line

zipInput = new GZIPInputStream(fis);
bis = new BufferedInputStream(zipInput);
bis.read(buffer);//here exception occurs

please help.


回答1:


This archieve really has been corrupted. You can form input stream from bytes:

InputStream bStream = new ByteArrayInputStream(bytes);

or from file:

InputStream bStream = new FileInputStream(fis);

ByteArrayOutputStream bOutStream = new ByteArrayOutputStream();

try{
    GZIPInputStream gis = new GZIPInputStream(bStream);
    byte[] buffer = new byte[1];
    int len;

at some iteration cycle will corrupt

    while((len = gis.read(buffer)) != -1){
        bOutStream.write(buffer, 0, len);
    }

    bOutStream.close();
    gis.close();

} catch (IOException e) {
    e.printStackTrace();
    bOutStream.close();
    //print unarchieved bytes
    System.out.println(new String(bOutStream.toByteArray()));
}

That's why it helps find the place of corruption. All bytes before this place will be shown properly.



来源:https://stackoverflow.com/questions/21151669/java-util-zip-zipexception-invalid-distance-too-far-back-while-decompressing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!