Writing uncompressed zip file

  • Thread starter Morten Omholt Alver
  • Start date
M

Morten Omholt Alver

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.
 
M

Morten Omholt Alver

Morten said:
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.
 
M

Mike Schilling

Morten said:
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.
 
M

Morten Omholt Alver

Mike said:
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.
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top