Using ZipInputStream efficiently

C

Chris Berg

Which one is best:

1:
DataInputStream dis=new DataInputStream(
new ZipInputStream(
new FileInputStream(filename));
2:
DataInputStream dis=new DataInputStream(
new ZipInputStream(
new BufferedInputStream(
new FileInputStream(filename))));
3:
DataInputStream dis=new DataInputStream(
new BufferedInputStream(
new ZipInputStream(
new FileInputStream(filename))));
4:
DataInputStream dis=new DataInputStream(
new BufferedInputStream(
new ZipInputStream(
new BufferedInputStream(
new FileInputStream(filename)))));


Chris
 
C

Chris Head

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris said:
Which one is best:

1:
DataInputStream dis=new DataInputStream(
new ZipInputStream(
new FileInputStream(filename));
2:
DataInputStream dis=new DataInputStream(
new ZipInputStream(
new BufferedInputStream(
new FileInputStream(filename))));
3:
DataInputStream dis=new DataInputStream(
new BufferedInputStream(
new ZipInputStream(
new FileInputStream(filename))));
4:
DataInputStream dis=new DataInputStream(
new BufferedInputStream(
new ZipInputStream(
new BufferedInputStream(
new FileInputStream(filename)))));


Chris


Hi,
I'm guessing either 2 or 4. I would guess that ZipInputStream might well
issue repeated small reads in the process of doing its normal operations
(though I don't know this for sure), so those should be coalesced by
using a BufferedInputStream between it and FileInputStream. However, the
fact that you're using DataInputStream tells me that you're probably
reading small amounts at a time from the resulting unzipped stream as
well, so buffering between DIS and ZIS might also be useful so that the
Zip algorithm can work on large blocks of data at a time.

I guess the real answer is: benchmark it.

Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)

iD8DBQFC7T4h6ZGQ8LKA8nwRAolOAJ9Qx1iTqjtgJcq4L2gWAIRvEQ4ueQCfXYca
0oGAnFjxwg9YN2adjZrs1+8=
=GQP8
-----END PGP SIGNATURE-----
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top