use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project POL-POM-5 by PlayOnLinux.
the class Tar method uncompress.
/**
* Uncompress a tar
*
* @param countingInputStream
* to count the number of byte extracted
* @param outputDir
* The directory where files should be extracted
* @return A list of extracted files
* @throws ArchiveException
* if the process fails
*/
private List<File> uncompress(final InputStream inputStream, CountingInputStream countingInputStream, final File outputDir, long finalSize, Consumer<ProgressEntity> stateCallback) {
final List<File> uncompressedFiles = new LinkedList<>();
try (ArchiveInputStream debInputStream = new ArchiveStreamFactory().createArchiveInputStream("tar", inputStream)) {
TarArchiveEntry entry;
while ((entry = (TarArchiveEntry) debInputStream.getNextEntry()) != null) {
final File outputFile = new File(outputDir, entry.getName());
if (entry.isDirectory()) {
LOGGER.info(String.format("Attempting to write output directory %s.", outputFile.getAbsolutePath()));
if (!outputFile.exists()) {
LOGGER.info(String.format("Attempting to createPrefix output directory %s.", outputFile.getAbsolutePath()));
Files.createDirectories(outputFile.toPath());
}
} else {
LOGGER.info(String.format("Creating output file %s (%s).", outputFile.getAbsolutePath(), entry.getMode()));
if (entry.isSymbolicLink()) {
Files.createSymbolicLink(Paths.get(outputFile.getAbsolutePath()), Paths.get(entry.getLinkName()));
} else {
try (final OutputStream outputFileStream = new FileOutputStream(outputFile)) {
IOUtils.copy(debInputStream, outputFileStream);
Files.setPosixFilePermissions(Paths.get(outputFile.getPath()), fileUtilities.octToPosixFilePermission(entry.getMode()));
}
}
}
uncompressedFiles.add(outputFile);
stateCallback.accept(new ProgressEntity.Builder().withPercent((double) countingInputStream.getCount() / (double) finalSize * (double) 100).withProgressText("Extracting " + outputFile.getName()).build());
}
return uncompressedFiles;
} catch (IOException | org.apache.commons.compress.archivers.ArchiveException e) {
throw new ArchiveException("Unable to extract the file", e);
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project tomee by apache.
the class BuildTomEEMojo method tarGz.
private void tarGz(final TarArchiveOutputStream tarGz, final File f, final String prefix) throws IOException {
final String path = f.getPath().replace(prefix, "").replace(File.separator, "/");
final TarArchiveEntry archiveEntry = new TarArchiveEntry(f, path);
if (isSh(path)) {
archiveEntry.setMode(0755);
}
tarGz.putArchiveEntry(archiveEntry);
if (f.isDirectory()) {
tarGz.closeArchiveEntry();
final File[] files = f.listFiles();
if (files != null) {
for (final File child : files) {
tarGz(tarGz, child, prefix);
}
}
} else {
IO.copy(f, tarGz);
tarGz.closeArchiveEntry();
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project tika by apache.
the class TarWriter method tarStoreBuffer.
private static void tarStoreBuffer(TarArchiveOutputStream zip, String name, byte[] dataBuffer) throws IOException {
TarArchiveEntry entry = new TarArchiveEntry(name);
entry.setSize(dataBuffer.length);
zip.putArchiveEntry(entry);
zip.write(dataBuffer);
zip.closeArchiveEntry();
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project cdap by caskdata.
the class LocalizationUtils method extractTar.
private static void extractTar(final TarArchiveInputStream tis, File targetDir) throws IOException {
TarArchiveEntry entry = tis.getNextTarEntry();
while (entry != null) {
File output = new File(targetDir, new File(entry.getName()).getName());
if (entry.isDirectory()) {
//noinspection ResultOfMethodCallIgnored
output.mkdirs();
} else {
//noinspection ResultOfMethodCallIgnored
output.getParentFile().mkdirs();
ByteStreams.copy(tis, Files.newOutputStreamSupplier(output));
}
entry = tis.getNextTarEntry();
}
}
use of org.apache.commons.compress.archivers.tar.TarArchiveEntry in project cdap by caskdata.
the class LocalizationUtilsTest method addFilesToTar.
private void addFilesToTar(TarArchiveOutputStream tos, File... filesToAdd) throws IOException {
for (File file : filesToAdd) {
TarArchiveEntry tarEntry = new TarArchiveEntry(file);
tos.putArchiveEntry(tarEntry);
if (file.isFile()) {
com.google.common.io.Files.copy(file, tos);
}
tos.closeArchiveEntry();
}
}
Aggregations