I'm creating compression and decompression app which are using xz compression method. But the compression and decompression are slower compared to another app which also uses the same compression method. For example, I have tried to decompress 15mb file into 40mb file and my code takes about 18 seconds, while it only takes about 4 seconds on another app.
I'm using XZInputStream from XZ for Java and TarArchiveInputStream from Apache Common Compress
public static void decompress(File file, String targetPath) {
try {
File outputFile = new File(targetPath);
FileInputStream fileInputStream = new FileInputStream(file);
XZInputStream xzInputStream = new XZInputStream(fileInputStream);
TarArchiveInputStream tarInputStream = new TarArchiveInputStream(xzInputStream);
TarArchiveEntry entry;
while ((entry = tarInputStream.getNextTarEntry()) != null) {
if (entry.isDirectory()) {
continue;
}
File curFile = new File(outputFile, entry.getName());
File parent = curFile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
IOUtils.copy(tarInputStream, new FileOutputStream(curFile));
}
} catch (FileNotFoundException e) {
Log.e("Exception", Log.getStackTraceString(e));
} catch (IOException e) {
Log.e("Exception", Log.getStackTraceString(e));
}
}