use of org.apache.commons.compress.archivers.ArchiveEntry in project grunt-maven-plugin by allegro.
the class TarUtil method untar.
public static void untar(File source, File target, Log logger) {
TarArchiveInputStream tarInput = null;
ArchiveEntry entry;
OutputStream output = null;
try {
tarInput = new TarArchiveInputStream(new FileInputStream(source));
entry = tarInput.getNextEntry();
while (entry != null) {
File outputFile = new File(target.getCanonicalPath() + File.separator + entry.getName());
if (entry.isDirectory()) {
logger.debug("creating dir at: " + outputFile.getCanonicalPath());
outputFile.mkdirs();
} else {
logger.debug("creating file at: " + outputFile.getCanonicalPath());
output = new FileOutputStream(outputFile);
IOUtils.copy(tarInput, output);
output.flush();
output.close();
}
entry = tarInput.getNextEntry();
}
} catch (IOException exception) {
throw new IllegalStateException(exception);
} finally {
IOUtils.closeQuietly(tarInput);
IOUtils.closeQuietly(output);
}
}
use of org.apache.commons.compress.archivers.ArchiveEntry in project presto by prestodb.
the class TargzBasedPackageSupplier method getRootDirectory.
private static String getRootDirectory(File packageFile) {
try (TarArchiveInputStream archiveInputStream = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(packageFile)))) {
ArchiveEntry entry = archiveInputStream.getNextEntry();
if (entry == null) {
throw new IllegalArgumentException(format("Archive is empty: %s", packageFile));
}
Path path = Paths.get(entry.getName());
return path.getName(0).toString();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.apache.commons.compress.archivers.ArchiveEntry in project presto by prestodb.
the class TargzBasedPackageSupplier method extractPackage.
private static void extractPackage(File packageFile, File outputDirectory) {
try (TarArchiveInputStream archiveInputStream = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(packageFile)))) {
while (true) {
ArchiveEntry entry = archiveInputStream.getNextEntry();
if (entry == null) {
break;
}
File output = new File(outputDirectory, entry.getName());
if (entry.isDirectory()) {
if (output.exists()) {
verify(output.isDirectory(), "package directory is not a directory: %s", output);
continue;
}
createDirectories(output.toPath());
} else {
File directory = output.getParentFile();
if (!directory.exists()) {
createDirectories(directory.toPath());
}
try (OutputStream outputStream = new FileOutputStream(output)) {
ByteStreams.copy(archiveInputStream, outputStream);
}
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.apache.commons.compress.archivers.ArchiveEntry in project ice by Netflix.
the class BillingFileProcessor method processBillingZipFile.
private void processBillingZipFile(File file, boolean withTags) throws IOException {
InputStream input = new FileInputStream(file);
ZipArchiveInputStream zipInput = new ZipArchiveInputStream(input);
try {
ArchiveEntry entry;
while ((entry = zipInput.getNextEntry()) != null) {
if (entry.isDirectory())
continue;
processBillingFile(entry.getName(), zipInput, withTags);
}
} catch (IOException e) {
if (e.getMessage().equals("Stream closed"))
logger.info("reached end of file.");
else
logger.error("Error processing " + file, e);
} finally {
try {
zipInput.close();
} catch (IOException e) {
logger.error("Error closing " + file, e);
}
try {
input.close();
} catch (IOException e1) {
logger.error("Cannot close input for " + file, e1);
}
}
}
use of org.apache.commons.compress.archivers.ArchiveEntry in project structr by structr.
the class UnarchiveCommand method handleArchiveInputStream.
private void handleArchiveInputStream(final ArchiveInputStream in, final App app, final SecurityContext securityContext, final Folder existingParentFolder) throws FrameworkException, IOException {
int overallCount = 0;
ArchiveEntry entry = in.getNextEntry();
while (entry != null) {
try (final Tx tx = app.tx(true, true, false)) {
// don't send notifications for bulk commands
int count = 0;
while (entry != null && count++ < 50) {
final String entryPath = "/" + PathHelper.clean(entry.getName());
logger.info("Entry path: {}", entryPath);
if (entry.isDirectory()) {
handleDirectory(securityContext, existingParentFolder, entryPath);
} else {
handleFile(securityContext, in, existingParentFolder, entryPath);
}
entry = in.getNextEntry();
overallCount++;
}
logger.info("Committing transaction after {} entries.", overallCount);
tx.success();
}
}
logger.info("Unarchived {} entries.", overallCount);
}
Aggregations