if (Files.notExists(destDir)) {
logger.trace("Create dir: {}", destDir);
Files.createDirectories(destDir);
}
TarArchiveInputStream in = new TarArchiveInputStream(new GzipCompressorInputStream(Files.newInputStream(tgzFile)));
TarArchiveEntry entry;
while ((entry = in.getNextTarEntry()) != null) {
if (entry.isDirectory()) {
Path dir = destDir.resolve(entry.getName());
logger.trace("Create dir {}", dir);
Files.createDirectories(dir);
} else {
Path file = destDir.resolve(entry.getName());
logger.trace("Create file {}: {} bytes", file, entry.getSize());
OutputStream out = Files.newOutputStream(file);
IOUtils.copy(in, out);
out.close();
}
}
in.close();
} catch (IOException e) {
throw new RuntimeIOException("Exception expanding " + tgzFile + " to " + destDir, e);
}
}