Я распаковываю огромный файл gz в java, файл gz составляет около 2 ГБ, а разархивированный файл - около 6 ГБ. время от времени процесс распаковки занимал вечность (часы), иногда он заканчивался в разумные сроки (например, менее 10 минут или быстрее).
У меня довольно мощный компьютер (8 ГБ ОЗУ, 4 процессора), можно ли улучшить приведенный ниже код? или использовать совершенно другую библиотеку?
Также я использовал Xms256m и Xmx4g для vm.
public static File unzipGZ(File file, File outputDir) {
GZIPInputStream in = null;
OutputStream out = null;
File target = null;
try {
// Open the compressed file
in = new GZIPInputStream(new FileInputStream(file));
// Open the output file
target = new File(outputDir, FileUtil.stripFileExt(file.getName()));
out = new FileOutputStream(target);
// Transfer bytes from the compressed file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Close the file and stream
in.close();
out.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return target;
}