Search code examples
javagzipnio

unzip .gz file in Java takes long time using GZInputStream and byte buffer


I have .gz file of size around 25 MB. I am trying to unzip it using the following code and it takes around 12 to 15 seconds every time for different buffer size like 1024,2048,4096 etc. I am not sure why it takes this much time. zip File size is only 25 MB. Is this normal time? Please guide. I am new to file programming and unzipping file. Thanks in advance.

EDIT: unzip file is size is 511 MB

InputStream is = new GZIPInputStream( new FileInputStream(f) );
BufferedReader br = new BufferedReader( new InputStreamReader(is) );
BufferedWriter dataFileWriter = new BufferedWriter(new FileWriter(dataFile));
char[] buff = new char[4096];
int len = 0;
while( (len = br.read( buff )) > 0 )
   dataFileWriter.write( buff, 0, len);

Solution

  • You don't say anything about your machine, so it is impossible to say if that's a normal time. On my 2 GHz i7 with an SSD, that takes about one second.