Runtime.getRuntime().exec(args);
LOGGER.info("Set execute permissions on " + file);
}
private void untarTarFile(File tarFile, File destDir) throws Exception {
TarArchiveInputStream tarInputStream = null;
try {
tarInputStream = new TarArchiveInputStream(new FileInputStream(tarFile));
TarArchiveEntry entry = null;
while ((entry = tarInputStream.getNextTarEntry()) != null) {
String name = entry.getName();
LOGGER.debug("Next file: " + name);
File destFile = new File(destDir, entry.getName());
if (entry.isDirectory()) {
destFile.mkdirs();
continue;
}
File destParent = destFile.getParentFile();
destParent.mkdirs();
OutputStream entryOutputStream = null;
try {
entryOutputStream = new FileOutputStream(destFile);
byte[] buffer = new byte[2048];
int length = 0;
while ((length = tarInputStream.read(buffer, 0, 2048)) != -1) {
entryOutputStream.write(buffer, 0, length);
}
} catch (Exception ex) {
LOGGER.error("Exception while expanding tar file", ex);
throw ex;
} finally {
if (entryOutputStream != null) {
try {
entryOutputStream.close();
} catch (Exception ex) {
LOGGER.warn("Failed to close entry output stream", ex);
}
}
}
}
} catch (Exception ex) {
LOGGER.error("Exception caught while untarring tar file: "
+ tarFile.getAbsolutePath(), ex);
throw ex;
} finally {
if (tarInputStream != null) {
try {
tarInputStream.close();
} catch (Exception ex) {
LOGGER.warn("Unable to close tar input stream: "
+ tarFile.getCanonicalPath(), ex);
}
}