Zip Hassles, EOFException.

A

Andrew Tucker

Hi, i am getting:
java.io.EOFException: Unexpected end of ZLIB input stream
while attempting to use java.util.zip.*

I have chased this up w/ groups.google and then w/ the bug parade at Sun.
It seems to be an unresolved issue.

I was wondering if comeone could take a quick look at the following method
and tell me (bugs aside) whether there is anything wrong with this.

private File uncompress(File f) throws Exception {
File toReturn = null;
try {
toReturn = new File("" + f.getName() + ".uncomp");

ZipInputStream zin = new ZipInputStream(new FileInputStream(f));
FileOutputStream out = new FileOutputStream(toReturn);
ZipEntry e;

byte[] buffer = new byte[512];
int len = 0;
while((e = zin.getNextEntry()) != null) {
System.out.println("looping, zip entry: " + e.getName());
while((len=zin.read(buffer)) != -1) {
System.out.println("" + len);
out.write(buffer, 0, len);
}
zin.closeEntry();
}
zin.close();
out.close();
} catch( Exception exc ) {
exc.printStackTrace();
throw new Exception("Exception occurred in method uncompress.");
}
return toReturn;
}
 
A

asjf

hi,

i can't see anything wrong with this, and it works fine for me (win2k,
java1.4.2). I tried running it on "src.zip" which is distributed with the
SDK and it had no troubles. What exactly is the stack trace? could the error
be from a corrupt zip file?

asjf
 
A

Andrew Tucker

Hi Roedy,

I thought perhaps you might be interested in the error msg and stack trace
for your error messages page. This one certainly had me stumped for quite a
while. Thankyou also for all your help directly and indirectly via 'the
glossary'. I have also included the code used to generate the zip files.
Forgive me mailing it here, i am currently also a victim of the 'virus
storm'.

java.io.EOFException: Unexpected end of ZLIB input stream
at java.util.zip.InflaterInputStream.fill(Unknown Source)
at java.util.zip.InflaterInputStream.read(Unknown Source)
at java.util.zip.ZipInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at ClientSide.uncompress(ClientSide.java:76)
at ClientSide.<init>(ClientSide.java:42)
at ClientSide.main(ClientSide.java:18)

private File compress(File f) throws Exception {
int entryCount = 0;
File toReturn = null;

try {
toReturn = new File(f.getName() + ".comp");
ZipOutputStream zos = new ZipOutputStream(new
FileOutputStream(toReturn));
FileInputStream in = new FileInputStream(f);
ZipEntry ze;

byte[] buffer = new byte[512];

while(in.read(buffer) != EOF) {
ze = new ZipEntry("" + ++entryCount);
// System.out.println("Going around again. entryCount: " +
entryCount);
zos.putNextEntry(ze);
zos.write(buffer);
}

return toReturn;
} catch( Exception exc ) {
exc.printStackTrace();
throw new Exception("Exception occurred in method send.");
}
}

cheers, Andrew.
 
A

Andrew Tucker

When reading elements of the zipfile, entry.getSize() always returns -1. I
am therefore getting a negative array size exception!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top