What's the optimum buffer size?

Hi everyone,
I'm having trouble with my unzipping method. The thing is when I unzip a smaller file, like something 200 kb, it unzips fine. But when it comes to large files, like something 10000 kb large, it doesn't unzip at all!
I'm guessing it has something to do with buffer size... or does it? Could someone please explain what is wrong?
Here's my code:
import java.io.*;
import java.util.zip.*;
  * Utility class with methods to zip/unzip and gzip/gunzip files.
public class ZipGzipper {
  public static final int BUF_SIZE = 8192;
  public static final int STATUS_OK          = 0;
  public static final int STATUS_OUT_FAIL    = 1; // No output stream.
  public static final int STATUS_ZIP_FAIL    = 2; // No zipped file
  public static final int STATUS_GZIP_FAIL   = 3; // No gzipped file
  public static final int STATUS_IN_FAIL     = 4; // No input stream.
  public static final int STATUS_UNZIP_FAIL  = 5; // No decompressed zip file
  public static final int STATUS_GUNZIP_FAIL = 6; // No decompressed gzip file
  private static String fMessages [] = {
    "Operation succeeded",
    "Failed to create output stream",
    "Failed to create zipped file",
    "Failed to create gzipped file",
    "Failed to open input stream",
    "Failed to decompress zip file",
    "Failed to decompress gzip file"
    *  Unzip the files from a zip archive into the given output directory.
    *  It is assumed the archive file ends in ".zip".
  public static int unzipFile (File file_input, File dir_output) {
    // Create a buffered zip stream to the archive file input.
    ZipInputStream zip_in_stream;
    try {
      FileInputStream in = new FileInputStream (file_input);
      BufferedInputStream source = new BufferedInputStream (in);
      zip_in_stream = new ZipInputStream (source);
    catch (IOException e) {
      return STATUS_IN_FAIL;
    // Need a buffer for reading from the input file.
    byte[] input_buffer = new byte[BUF_SIZE];
    int len = 0;
    // Loop through the entries in the ZIP archive and read
    // each compressed file.
    do {
      try {
        // Need to read the ZipEntry for each file in the archive
        ZipEntry zip_entry = zip_in_stream.getNextEntry ();
        if (zip_entry == null) break;
        // Use the ZipEntry name as that of the compressed file.
        File output_file = new File (dir_output, zip_entry.getName ());
        // Create a buffered output stream.
        FileOutputStream out = new FileOutputStream (output_file);
        BufferedOutputStream destination =
          new BufferedOutputStream (out, BUF_SIZE);
        // Reading from the zip input stream will decompress the data
        // which is then written to the output file.
        while ((len = zip_in_stream.read (input_buffer, 0, BUF_SIZE)) != -1)
          destination.write (input_buffer, 0, len);
        destination.flush (); // Insure all the data  is output
        out.close ();
      catch (IOException e) {
        return STATUS_GUNZIP_FAIL;
    } while (true);// Continue reading files from the archive
    try {
      zip_in_stream.close ();
    catch (IOException e) {}
    return STATUS_OK;
  } // unzipFile
} // ZipGzipperThanks!!!!

Any more hints on how to fix it? I've been fiddling
around with it for an hour..... and throwing more
exceptions. But I'm still no closer to debugging it!
ThanksDid you add:
e.printStackTrace();
to your catch blocks?
Didn't you in that case get an exception which says something similar to:
java.io.FileNotFoundException: C:\TEMP\test\com\blah\icon.gif (The system cannot find the path specified)
     at java.io.FileOutputStream.open(Native Method)
     at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
     at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
     at Test.unzipFile(Test.java:68)
     at Test.main(Test.java:10)Which says that the error is thrown here:
     // Create a buffered output stream.
     FileOutputStream out = new FileOutputStream(output_file);Kaj

Similar Messages

  • What is the default buffer size if we dont specify in buffer write?

    If we dont specify what is the default buffer size in BufferedWriter. How to increase/decrease the size of it?
    What is the purpose of flush?
    If flush() is not used, only partial content is written to the file. Is it because of the default size of the buffer.

    THis is the bufferedwriter class, it helps to look at them, look at the bold underlined, thats answers your defualt buffer size
    * @(#)BufferedWriter.java     1.26 03/12/19
    * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
    * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    package java.io;
    * Write text to a character-output stream, buffering characters so as to
    * provide for the efficient writing of single characters, arrays, and strings.
    * <p> The buffer size may be specified, or the default size may be accepted.
    * The default is large enough for most purposes.
    * <p> A newLine() method is provided, which uses the platform's own notion of
    * line separator as defined by the system property <tt>line.separator</tt>.
    * Not all platforms use the newline character ('\n') to terminate lines.
    * Calling this method to terminate each output line is therefore preferred to
    * writing a newline character directly.
    * <p> In general, a Writer sends its output immediately to the underlying
    * character or byte stream. Unless prompt output is required, it is advisable
    * to wrap a BufferedWriter around any Writer whose write() operations may be
    * costly, such as FileWriters and OutputStreamWriters. For example,
    * <pre>
    * PrintWriter out
    * = new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));
    * </pre>
    * will buffer the PrintWriter's output to the file. Without buffering, each
    * invocation of a print() method would cause characters to be converted into
    * bytes that would then be written immediately to the file, which can be very
    * inefficient.
    * @see PrintWriter
    * @see FileWriter
    * @see OutputStreamWriter
    * @version      1.26, 03/12/19
    * @author     Mark Reinhold
    * @since     JDK1.1
    public class BufferedWriter extends Writer {
    private Writer out;
    private char cb[];
    private int nChars, nextChar;
    private static int defaultCharBufferSize = 8192;
    * Line separator string. This is the value of the line.separator
    * property at the moment that the stream was created.
    private String lineSeparator;
    * Create a buffered character-output stream that uses a default-sized
    * output buffer.
    * @param out A Writer
    *public BufferedWriter(Writer out) {*
    *     this(out, defaultCharBufferSize);*
    * Create a new buffered character-output stream that uses an output
    * buffer of the given size.
    * @param out A Writer
    * @param sz Output-buffer size, a positive integer
    * @exception IllegalArgumentException If sz is <= 0
    public BufferedWriter(Writer out, int sz) {
         super(out);
         if (sz <= 0)
         throw new IllegalArgumentException("Buffer size <= 0");
         this.out = out;
         cb = new char[sz];
         nChars = sz;
         nextChar = 0;
         lineSeparator =     (String) java.security.AccessController.doPrivileged(
    new sun.security.action.GetPropertyAction("line.separator"));
    /** Check to make sure that the stream has not been closed */
    private void ensureOpen() throws IOException {
         if (out == null)
         throw new IOException("Stream closed");
    * Flush the output buffer to the underlying character stream, without
    * flushing the stream itself. This method is non-private only so that it
    * may be invoked by PrintStream.
    void flushBuffer() throws IOException {
         synchronized (lock) {
         ensureOpen();
         if (nextChar == 0)
              return;
         out.write(cb, 0, nextChar);
         nextChar = 0;
    * Write a single character.
    * @exception IOException If an I/O error occurs
    public void write(int c) throws IOException {
         synchronized (lock) {
         ensureOpen();
         if (nextChar >= nChars)
              flushBuffer();
         cb[nextChar++] = (char) c;
    * Our own little min method, to avoid loading java.lang.Math if we've run
    * out of file descriptors and we're trying to print a stack trace.
    private int min(int a, int b) {
         if (a < b) return a;
         return b;
    * Write a portion of an array of characters.
    * <p> Ordinarily this method stores characters from the given array into
    * this stream's buffer, flushing the buffer to the underlying stream as
    * needed. If the requested length is at least as large as the buffer,
    * however, then this method will flush the buffer and write the characters
    * directly to the underlying stream. Thus redundant
    * <code>BufferedWriter</code>s will not copy data unnecessarily.
    * @param cbuf A character array
    * @param off Offset from which to start reading characters
    * @param len Number of characters to write
    * @exception IOException If an I/O error occurs
    public void write(char cbuf[], int off, int len) throws IOException {
         synchronized (lock) {
         ensureOpen();
    if ((off < 0) || (off > cbuf.length) || (len < 0) ||
    ((off + len) > cbuf.length) || ((off + len) < 0)) {
    throw new IndexOutOfBoundsException();
    } else if (len == 0) {
    return;
         if (len >= nChars) {
              /* If the request length exceeds the size of the output buffer,
              flush the buffer and then write the data directly. In this
              way buffered streams will cascade harmlessly. */
              flushBuffer();
              out.write(cbuf, off, len);
              return;
         int b = off, t = off + len;
         while (b < t) {
              int d = min(nChars - nextChar, t - b);
              System.arraycopy(cbuf, b, cb, nextChar, d);
              b += d;
              nextChar += d;
              if (nextChar >= nChars)
              flushBuffer();
    * Write a portion of a String.
    * <p> If the value of the <tt>len</tt> parameter is negative then no
    * characters are written. This is contrary to the specification of this
    * method in the {@linkplain java.io.Writer#write(java.lang.String,int,int)
    * superclass}, which requires that an {@link IndexOutOfBoundsException} be
    * thrown.
    * @param s String to be written
    * @param off Offset from which to start reading characters
    * @param len Number of characters to be written
    * @exception IOException If an I/O error occurs
    public void write(String s, int off, int len) throws IOException {
         synchronized (lock) {
         ensureOpen();
         int b = off, t = off + len;
         while (b < t) {
              int d = min(nChars - nextChar, t - b);
              s.getChars(b, b + d, cb, nextChar);
              b += d;
              nextChar += d;
              if (nextChar >= nChars)
              flushBuffer();
    * Write a line separator. The line separator string is defined by the
    * system property <tt>line.separator</tt>, and is not necessarily a single
    * newline ('\n') character.
    * @exception IOException If an I/O error occurs
    public void newLine() throws IOException {
         write(lineSeparator);
    * Flush the stream.
    * @exception IOException If an I/O error occurs
    public void flush() throws IOException {
         synchronized (lock) {
         flushBuffer();
         out.flush();
    * Close the stream.
    * @exception IOException If an I/O error occurs
    public void close() throws IOException {
         synchronized (lock) {
         if (out == null)
              return;
         flushBuffer();
         out.close();
         out = null;
         cb = null;
    What Flush(); does
    Example, you have a file called c, your writer is b and buffereredwriter is a. so your programs calls a, a talks to b, and b talks to c. when you call the Flush method, the information is sent to the outfile which is c immediately before you even close the file, because when you write to the file, it does not write directly, it writes to a buffer, so flush actually causes the buffer to write to file. Also if you call the close method on that file without the flush, the buffer will still get flushed.
    consider BufferedWriter c = new BufferedWriter(new PrintWriter("c:\\c"));
    you wrap printwriter into a buffered writer, now if you close this "connection" to the file, the buffer will get flushed, noting that all the data is sitting in the buffered and not yet in the file, and this happens if something dont break...

  • Doing Buffered Event count by using Count Buffered Edges.vi, what is the max buffer size allowed?

    I'm currently using Count Buffered Edges.vi to do Buffered Event count with the following settings,
    Source : Internal timebase, 100Khz, 10usec for each count
    gate : use the function generator to send in a 50Hz signal(for testing purpose only). Period of 0.02sec
    the max internal buffer size that i can allocate is only about 100~300. Whenever i change both the internal buffer size and counts to read to a higher value, this vi don't seem to function well. I need to have a buffer size of at least 2000.
    1. is it possible to have a buffer size of 2000? what is the problem causing the wrong counter value?
    2. also note that the size of max internal buffer varies w
    ith the frequency of signal sent to the gate, why is this so? eg: buffer size get smaller as frequency decrease.
    3. i'll get funny response and counter value when both the internal buffer size and counts to read are not set to the same. Why is this so? is it a must to set both value the same?
    thks and best regards
    lyn

    Hi,
    I have tried the same example, and used a 100Hz signal on the gate. I increased the buffer size to 2000 and I did not get any errors. The buffer size does not get smaller when increasing the frequency of the gate signal; simply, the number of counts gets smaller when the gate frequency becomes larger. The buffer size must be able to contain the number of counts you want to read, otherwise, the VI might not function correctly.
    Regards,
    RamziH.

  • What is the maximal Buffer size for traditional NI-DAQ?

    Hello,
    I use a new NI S 6115 DAQ with four channels. The sampling rate is 10 MHz. I would like to enlarge the amount of samples, that I store in memory RAM of my PC.
    Around 8300000 samples/channel I get a heap error (at configuration time).
    Is this a LabView or a Windows problem?
    When a trigger occurs, I read the data and store it to hard disk.
    PC: 3 GHz, 1 GByte RAM. Windows 2000, LabView 7.0

    Hello,
    the problem is when you use a sampling rate of 10 MHz on four channels you need a memory of 80MB(10Msample x 2Byte x 4Channels). The Input FIFO only has a memory of 64MB.
    That means you can only use 3 channels (60MB) with such a high sampling rate.
    Regards,
    Michael Sallaberger

  • What's the optimum version of Safari for OS 10.3.9?

    My first post here.
    What is the optimum version of Safari for use on a PowerBook G3 "Pismo" running OS 10.3.9? I'm currently running 1.2 (v 125). I've downloaded 1.3.1 but when I try to install it says "Not compatible with this system." Is there some version in between that would work better? If so, I haven't been able to find it, and the Update Software feature doesn't find it either.
    I did upgrade my firmware at some point, but I don't remember how to look up the version. Any help most appreciated.

    Hi and Welcome to Apple Discussions
    The highest version for Panther is 1.3.2.
    Before you can install 1.3.1, you need to install 1.3. This may get you there: Apply the 10.3.9 Combined Update. Do not use the computer while the Installer is running. Once complete you'll need to restart the computer.
    Then, via your Finder, go to your Applications>Utilities folder. Open Disk Utility. When open, click on the HD on the left, then First Aid Panel>Repair Permissions on the right. Once complete, open Safari.
    When the Safari browser is open, go to the Safari Menu>About Safari. Which version are you using? If it is 1.3.2, then you're good to go. If it is 1.3, then run the 1.3.1 installer again. Once finished (I believe you'll have to restart), run the 1.3.2 update. Once the installer/restart is complete again "repair permissions".

  • What's the sga max size for a 32bit windows server?

    Hi,
    I have a 32bit Windows Server with 16G of RAM... What is the SGA max size that I can setup?

    Depending on your version of Windows and your version of Oracle there are methods to increase the usuable memory available to Oracle including the MS \3GB and \PAE switches and the AWE memory extention feature.
    Oracle has notes on the subject:
    Windows Memory Configuration: 32-bit and 64-bit 873752.1 plus notes 46053.1 and 46001.1
    How to use Very Large Memory, higher than 4Gb on Windows 2003 32 bit #342080.1
    HTH -- Mark D Powell --

  • What is the best font size for text when making a book in iBooks Author? My present font is Baskerville at 20 pt.

    What is the best font size for text when making a book in iBooks Author? My present font is Baskerville at 20 pt.

    For what audience? What reading level? Which Flesch-Kincaid index? What type of content? How much white space? What language(s)?

  • What is the max file size that a Adapter Engine [J2SE] can handle ?

    We are having a scenario where a 4 GB compressed file needs to be sent across without mapping, I'm trying to explore the possible options to tackle this scenario.
    Some of the options, we are considering :
    - Sending a file from one Adapter Engine [J2SE] to another Adapter Engine [J2SE] bypassing PI. Adapter Logs will be monitored. What is the maximum file size that can be then handled assuming a standard installation ?
    - What is the max file size that Adapter Engine [J2SE] can send through PI without mapping?
    Any help with the above options or with any other possible solutions to handle extremely large file transfers will be much appreciated.

    Hi,
    j2se is not a good option here
    if you have 4gb then you need a copy solution
    a) build an proxy that will just copy the file from sender dest to receiver
    b) build an adapter that will do the same as proxy)
    this way processing of this message will be controlled with SAP PI/XI
    it will be as quick as copy & paste of the 4gb file
    I did the a) for one of the flow for 300 mb and it works perfectly
    Regards,
    Michal Krawczyk

  • How do you increase the Streaming buffer size in iTunes 10

    When I try to listen to the radio in ITunes it plays for 30 seconds then says rebuffering stream.
    I just upgraded to an iMac and my old dinasaur G4 does not have this problem.
    I've read things saying to increase the Streaming buffer size but I don't see how to do this anywhere.
    J

    I don't think that is possible with newer iTunes versions.

  • What are the optimum wifi router settings for ipad mini

    My new iPad Mini WiFi access is really slow on my home WiFi network.  All my other WiFi devices are working fine.  I have a D-Link DIR655 Wireless Router - What are the optimum router setting to ensure compatibility with the iPad?

    I'm having the same issue with a TP-LINK router.

  • What's the FPGA step size and how to calculate it?

    Hi there,
    I inherited an vi with problem in it. It's basically reading the binary file then display it. So the vi reads the binary file by using Read From Binary File, the output data from this function then sends to FPGA after multiply a number (32767/10). But unfortunately I got a wrong output. The final output value for some reasons looks got attenuated. People told me maybe it's related to the FPGA step size, so I want to know what is the FPGA step size and how to calculate it. Can someone answer my questions here?
    Thanks in advanced!!!

    Hi Weny,
    It sounds like you are trying to find out the output resolution of your FPGA module.  It would be helpful if you provided what FPGA module you are using in your tests so we know what information to provide.  For instance, the R Series Manual provides information on how to calculate the required DAC output code to generate the desired output voltage.  You should also try to keep the accuracy of your device in mind.  The analog output signal you are generating will be subject to gain, offset, and noise errors.  You can use the specifications sheet (such as the R Series Specifications) of your device to determine what accuracy your board will have.  The specs also provide information on the resolution of the board.  You can search ni.com for the manual and specifications for your particular device if you are not using R Series. 
    Regards,
    Browning G
    FlexRIO R&D

  • HT4818 What is the best Partition size for a windows 7 Home Premium. I'm trying to install Windows using Boot camp

    What is the best Partition size for a windows 7 Home Premium. I'm trying to install Windows using Boot camp

    Go into your system preferences and click the startup disk icon then select your Mac HD. 

  • What is the best actual size and resolution to save photos to put on your iPhone?

    What is the best actual size and resolution to save photos to be easily viewed on IPhone?

    Sorry, this is my first use of this support site.  I didn't realize that it was only for technical questions.  I am not the one who loses his iPhone, but I just wanted to provide some help to our family member who does.  He is usually a very responsible person, but he has lost his phone more than once.

  • What is the best image size format for imovie iOS

    I want to create a few black images with white letters as title slides and use them with some of my videos I am creating using imovie with my new ipad3.
    What is the best image size?
    thanks!
    Jeremy

    It all depends on what you want to do with the images.
    If you don't want to do any moves on the images then make them the exact size of the video.
    The iPad 3 edits in full HD, 1920 x 1080.
    If you want to do small moves, then make is larger.
    But keep the 1920 x 1080 dimensions otherwise iMovie just chops the image to that ratio.
    good luck

  • My Macbook Mavericks pro does connect well to a data projector, even after following the process recommended, what is the optimum display settings? Has anybody else had this problem, I'm close to going back to PC's

    My Macbook pro Mavericks does not connect well to a data project even after following the recommended process, Has anybody else struck this problem, what is the optimum display setting? Im close to going back to PCs

    You said " digital AV Adapter and thunderbolt". Do you mean Thunderbolt/min displayport to HDMI adapter?
    It appears you are using the free version of the Display Menu app.
    What does the Apple Display properties show? System Preferences>Displays>Display show?
    Look at the projector/go to the manufacturer's support site and find the native resolution of the projector.
    Googling for Sori data projector id not produce any hits

Maybe you are looking for