🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8714

ZipOutputStream question - please help!!!

#8714
From: Yonatan Taub
Date: Thu, 08 Mar 2001 22:00
118 lines
3711 bytes
Hello!

I've written a simple object which accepts a File[] array and compresses it
with a ZipOutputStream object to a given OutputStream.
It works fine. The only problem is when I try to compress about 12MB, it
take about 50 seconds to complete while WinZip does it in 6 seconds.

Does my code has a logical flaw? Do I need to do something with the
buffering?

The compressor object:

import java.util.zip.*;
import java.io.*;


/**
 * This class compresses files with the zip format and writes the output to
a specified OutputStream.
 */

public class ZipCompressor {

  private ZipOutputStream out;


  /**
   * The constructor accepts an OutputStream object to which the data will
be written to.
   *
   * @param outputStream - the outputstream to which the compressed files
will be written.
   */

  public ZipCompressor(OutputStream outputStream) {
    out = new ZipOutputStream(new BufferedOutputStream(outputStream));
  }


  /**
   * The method accepts a File array containing the files to compress.
   *
   * @param files - a File array containing the desired files to compress.
   *
   * @throws FileNotFoundException - if a file in the array is not found.
   * @throws IOException - if an IOException occurs.
   */

   public void compressFiles(File[] files) throws FileNotFoundException,
IOException {
     for(int i = 0; i < files.length; i++)
     {
       String fileName = files[i].getName();

       out.putNextEntry(new ZipEntry(fileName));
       BufferedReader in = new BufferedReader(new FileReader(files[i]));

       int c;

       while((c = in.read()) != -1)
         out.write(c);

       in.close();

     } // end for loop
   }


   /**
    * Writes the compressed data to the outputstream (which was specified in
the constructor).
    *
    * @throws IOException - if the closing the stream fails.
    */

   public void write() throws IOException {
     out.flush();
     out.close();
   }

} // end class ZipCompressor


============================================================================
============
The main() :

import java.io.*;

public class Test {


  public static void main(String[] args) {

    File[] files = {
                     new File("d:/java/tests/tests.jpr"),
                     new File("D:/JBuilder4/jdk1.3/jre/lib/rt.jar"),
                   };

    long start = System.currentTimeMillis();

    try {
      ZipCompressor compressor = new ZipCompressor(new
FileOutputStream("d:/test.zip"));
      compressor.compressFiles(files);
      compressor.write();
    } catch(Exception x) { x.printStackTrace(); }

    long stop = System.currentTimeMillis();

    System.out.println("Total seconds: " + (stop - start) / 1000);
  }

} // end class Test



Thanks!!!!
Technical Details
Message-ID: <3aa80218_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!news.maxwell.syr.edu!ptdnetP!newsgate.ptd.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!dnews!132.64.13.60

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,f1b1ab5b0816f6b8,start
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-08 14:16:07 PST
From: "Yonatan Taub" <yonatanta@bashan.co.il>
Newsgroups: borland.public.jbuilder.java.language
Subject: ZipOutputStream question - please help!!!
Date: Fri, 9 Mar 2001 00:00:34 +0200
Lines: 120
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 132.64.13.60
Message-ID: <3aa80218_1@dnews>
X-Trace: 8 Mar 2001 14:05:12 -0800, 132.64.13.60
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.wirehub.nl!news.maxwell.syr.edu!ptdnetP!newsgate.ptd.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!dnews!132.64.13.60