Writing uncompressed zip file

Discussion in 'Java' started by Morten Omholt Alver, Oct 7, 2008.

  1. Hi,

    I'm using java.util.ZipOutputStream to write a zip file regularly, and
    I'm trying to speed up the process by writing uncompressed entries to
    the zip file (I don't really need compression). I've tried two ways of
    achieving this.

    First, calling out.setMethod(ZipOutputStream.STORED) before writing any
    entries (out is the ZipOutputStrean instance). This should set
    uncompressed mode according to the Javadoc. When I add this call, the
    entries don't seem to be written to the zip file, and I get a
    "java.util.zip.ZipException: ZIP file must have at least one entry" when
    I call close() on the ZipOutputStream. Without calling setMethod(), the
    zip file is written without error.

    Second, calling entry.setMethod(ZipEntry.STORED) for each ZipEntry
    before or after calling out.putNextEntry(entry). This gives the same result.

    Is there something else I need to do when writing uncompressed zip
    files, or is something broken here?

    I'm running under Windows XP with Java SE 1.6.0_06.


    --
    Morten
     
    Morten Omholt Alver, Oct 7, 2008
    #1
    1. Advertising

  2. Morten Omholt Alver wrote:
    > Hi,
    >
    > I'm using java.util.ZipOutputStream to write a zip file regularly, and
    > I'm trying to speed up the process by writing uncompressed entries to
    > the zip file (I don't really need compression). I've tried two ways of
    > achieving this.
    >
    > First, calling out.setMethod(ZipOutputStream.STORED) before writing any
    > entries (out is the ZipOutputStrean instance). This should set
    > uncompressed mode according to the Javadoc. When I add this call, the
    > entries don't seem to be written to the zip file, and I get a
    > "java.util.zip.ZipException: ZIP file must have at least one entry" when
    > I call close() on the ZipOutputStream. Without calling setMethod(), the
    > zip file is written without error.
    >
    > Second, calling entry.setMethod(ZipEntry.STORED) for each ZipEntry
    > before or after calling out.putNextEntry(entry). This gives the same
    > result.


    I just realized I can call out.setLevel(Deflater.NO_COMPRESSION), so I'm
    trying that. I'm still puzzled by the effects of using the setMethod()
    call, though.


    --
    Morten
     
    Morten Omholt Alver, Oct 7, 2008
    #2
    1. Advertising

  3. Morten Omholt Alver wrote:
    >
    > I just realized I can call out.setLevel(Deflater.NO_COMPRESSION), so
    > I'm trying that. I'm still puzzled by the effects of using the
    > setMethod() call, though.


    If it's really as simple as flipping the setLevel parameter, you might
    try both compressed and uncompressed. I wouldn't be shocked if you
    found that compression winds up being faster, with the lowered I/O
    more than making up for the additional CPU.
     
    Mike Schilling, Oct 7, 2008
    #3
  4. Mike Schilling wrote:
    > Morten Omholt Alver wrote:
    >> I just realized I can call out.setLevel(Deflater.NO_COMPRESSION), so
    >> I'm trying that. I'm still puzzled by the effects of using the
    >> setMethod() call, though.

    >
    > If it's really as simple as flipping the setLevel parameter, you might
    > try both compressed and uncompressed. I wouldn't be shocked if you
    > found that compression winds up being faster, with the lowered I/O
    > more than making up for the additional CPU.


    Good point - I'll have a look at it and see how it works.


    --
    Morten
     
    Morten Omholt Alver, Oct 8, 2008
    #4
    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. Jim Schlemmer
    Replies:
    6
    Views:
    2,408
    Josef Garvi
    Apr 16, 2004
  2. Replies:
    1
    Views:
    391
    Cousin Stanley
    Sep 18, 2004
  3. Fredrik Lundh

    Re: uncompressed size of .gz file

    Fredrik Lundh, Sep 19, 2004, in forum: Python
    Replies:
    1
    Views:
    422
    Benjamin Niemann
    Sep 20, 2004
  4. Heiko Wundram

    Re: uncompressed size of .gz file

    Heiko Wundram, Sep 20, 2004, in forum: Python
    Replies:
    5
    Views:
    352
    Steve Holden
    Sep 20, 2004
  5. abcd
    Replies:
    7
    Views:
    529
    Edward Elliott
    May 1, 2006
Loading...

Share This Page