Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Zip Hassles, EOFException.

45 views
Skip to first unread message

Andrew Tucker

unread,
Sep 22, 2003, 7:47:09 AM9/22/03
to
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;
}


asjf

unread,
Sep 22, 2003, 9:33:53 AM9/22/03
to
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

"Andrew Tucker" <andrew...@optusnet.com.au> wrote in message
news:3f6e...@news.comindico.com.au...

Roedy Green

unread,
Sep 22, 2003, 3:18:17 PM9/22/03
to
On Mon, 22 Sep 2003 11:47:09 GMT, "Andrew Tucker"
<andrew...@optusnet.com.au> wrote or quoted :

>ZipInputStream zin = new ZipInputStream(new FileInputStream(f));

Try using ZipFile rather than ZipInputStream.

See http://mindprod.com/jgloss/zip.html for why

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Andrew Tucker

unread,
Sep 22, 2003, 9:02:52 PM9/22/03
to
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.

"Roedy Green" <ro...@mindprod.com> wrote in message
news:lmiumvkac5stnqv7l...@4ax.com...

Andrew Tucker

unread,
Sep 22, 2003, 10:27:32 PM9/22/03
to
When reading elements of the zipfile, entry.getSize() always returns -1. I
am therefore getting a negative array size exception!

"Roedy Green" <ro...@mindprod.com> wrote in message
news:lmiumvkac5stnqv7l...@4ax.com...

Roedy Green

unread,
Sep 23, 2003, 3:12:12 PM9/23/03
to
On Tue, 23 Sep 2003 02:27:32 GMT, "Andrew Tucker"
<andrew...@optusnet.com.au> wrote or quoted :

>When reading elements of the zipfile, entry.getSize() always returns -1. I


>am therefore getting a negative array size exception!

read http://mindprod.com/jgloss/zip.html to explain why.

Andrew Tucker

unread,
Sep 24, 2003, 9:32:59 AM9/24/03
to
Sorry Roedy, my mistake. Thankyou.

"Roedy Green" <ro...@seewebsite.com> wrote in message
news:tn41nv4tp1618m822...@4ax.com...

0 new messages