Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Zip Hassles, EOFException.

Reply
Thread Tools

Zip Hassles, EOFException.

 
 
Andrew Tucker
Guest
Posts: n/a
 
      09-22-2003
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;
}


 
Reply With Quote
 
 
 
 
asjf
Guest
Posts: n/a
 
      09-22-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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;
> }
>
>



 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      09-22-2003
On Mon, 22 Sep 2003 11:47:09 GMT, "Andrew Tucker"
<(E-Mail Removed)> 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.
 
Reply With Quote
 
Andrew Tucker
Guest
Posts: n/a
 
      09-23-2003
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:1

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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Mon, 22 Sep 2003 11:47:09 GMT, "Andrew Tucker"
> <(E-Mail Removed)> 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.



 
Reply With Quote
 
Andrew Tucker
Guest
Posts: n/a
 
      09-23-2003
When reading elements of the zipfile, entry.getSize() always returns -1. I
am therefore getting a negative array size exception!

"Roedy Green" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Mon, 22 Sep 2003 11:47:09 GMT, "Andrew Tucker"
> <(E-Mail Removed)> 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.



 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      09-23-2003
On Tue, 23 Sep 2003 02:27:32 GMT, "Andrew Tucker"
<(E-Mail Removed)> 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.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Andrew Tucker
Guest
Posts: n/a
 
      09-24-2003
Sorry Roedy, my mistake. Thankyou.

"Roedy Green" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Tue, 23 Sep 2003 02:27:32 GMT, "Andrew Tucker"
> <(E-Mail Removed)> 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.
>
> --
> Canadian Mind Products, Roedy Green.
> Coaching, problem solving, economical contract programming.
> See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Possibility to add a zip-file to a new zip-file with "add to zip" (right-click) ?? erikkie@casema.nl Computer Support 4 06-26-2006 12:18 AM
uploading and receiving zip file(java.util.zip) ? sunil_varma Java 1 02-06-2006 10:37 AM
java.util.zip.ZipException: error in opening zip file HARI OM Java 0 05-03-2005 05:02 PM
java.util.zip.ZipException: error in opening zip file hari_om@hotmail.com Java 0 05-03-2005 04:47 PM
java.util.zip - problem opening some legitimite me zip files Alex Hunsley Java 1 09-16-2004 02:06 PM



Advertisments