Zip Hassles, EOFException.

Discussion in 'Java' started by Andrew Tucker, Sep 22, 2003.

  1. 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;
    }
    Andrew Tucker, Sep 22, 2003
    #1
    1. Advertising

  2. Andrew Tucker

    asjf Guest

    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" <> wrote in message
    news:...
    > 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, Sep 22, 2003
    #2
    1. Advertising

  3. Andrew Tucker

    Roedy Green Guest

    On Mon, 22 Sep 2003 11:47:09 GMT, "Andrew Tucker"
    <> 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.
    Roedy Green, Sep 22, 2003
    #3
  4. 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" <> wrote in message
    news:...
    > On Mon, 22 Sep 2003 11:47:09 GMT, "Andrew Tucker"
    > <> 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, Sep 23, 2003
    #4
  5. When reading elements of the zipfile, entry.getSize() always returns -1. I
    am therefore getting a negative array size exception!

    "Roedy Green" <> wrote in message
    news:...
    > On Mon, 22 Sep 2003 11:47:09 GMT, "Andrew Tucker"
    > <> 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, Sep 23, 2003
    #5
  6. Andrew Tucker

    Roedy Green Guest

    On Tue, 23 Sep 2003 02:27:32 GMT, "Andrew Tucker"
    <> 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.
    Roedy Green, Sep 23, 2003
    #6
  7. Sorry Roedy, my mistake. Thankyou.

    "Roedy Green" <> wrote in message
    news:...
    > On Tue, 23 Sep 2003 02:27:32 GMT, "Andrew Tucker"
    > <> 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.
    Andrew Tucker, Sep 24, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Baer

    EOFException at ObjectInputStream

    David Baer, Feb 25, 2004, in forum: Java
    Replies:
    2
    Views:
    15,021
    David Baer
    Feb 26, 2004
  2. A. Farber
    Replies:
    3
    Views:
    6,483
    A. Farber
    Mar 21, 2006
  3. Stefan Weber

    EOFException after closing a socket

    Stefan Weber, Aug 19, 2006, in forum: Java
    Replies:
    2
    Views:
    2,834
  4. Replies:
    1
    Views:
    399
    pundeerd
    May 4, 2007
  5. Giles Bowkett

    leopard update - any Ruby hassles?

    Giles Bowkett, Dec 14, 2007, in forum: Ruby
    Replies:
    6
    Views:
    99
    John Joyce
    Dec 14, 2007
Loading...

Share This Page