Java. Util. Zip. Zipexception: Invalid Distance Too Far Back While Decompressing

Java. Util. Zip. Zipexception: Invalid Distance Too Far Back While Decompressing

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.

3

2 Answers

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.

When i have this problem last time - i used apache poi to edit word files and i had to resave files created in Microsoft Office using libre Office as word 2007. Then this error gone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.