I will unzip the huge gz file in java, the gz file is about 2 gb and the unzipped file is about 6 gb. from time to time the unpacking process lasts forever (hours), sometimes it ends in a reasonable time (for example, less than 10 minutes or faster).
I have a pretty powerful box (8 GB of RAM, 4-processor), is there any way to improve the code below? or use a completely different library?
Also I used Xms256m and Xmx4g for vm.
public static File unzipGZ(File file, File outputDir) {
GZIPInputStream in = null;
OutputStream out = null;
File target = null;
try {
in = new GZIPInputStream(new FileInputStream(file));
target = new File(outputDir, FileUtil.stripFileExt(file.getName()));
out = new FileOutputStream(target);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return target;
}
source
share