List of usage examples for org.apache.commons.compress.archivers.tar TarArchiveInputStream TarArchiveInputStream
public TarArchiveInputStream(InputStream is)
From source file:com.openshift.client.utils.TarFileUtils.java
public static boolean hasGitFolder(InputStream inputStream) throws IOException { TarArchiveInputStream tarInputStream = null; try {//from w w w.ja v a2 s.co m boolean gitFolderPresent = false; tarInputStream = new TarArchiveInputStream(new GzipCompressorInputStream(inputStream)); for (TarArchiveEntry entry = null; (entry = tarInputStream.getNextTarEntry()) != null;) { if (GIT_FOLDER_NAME.equals(entry.getName()) && entry.isDirectory()) { gitFolderPresent = true; break; } } return gitFolderPresent; } finally { StreamUtils.close(tarInputStream); } }
From source file:com.twitter.heron.downloader.Extractor.java
static void extract(InputStream in, Path destination) throws IOException { try (final BufferedInputStream bufferedInputStream = new BufferedInputStream(in); final GzipCompressorInputStream gzipInputStream = new GzipCompressorInputStream( bufferedInputStream); final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(gzipInputStream)) { final String destinationAbsolutePath = destination.toFile().getAbsolutePath(); TarArchiveEntry entry;/*from ww w .j a v a 2s. c om*/ while ((entry = (TarArchiveEntry) tarInputStream.getNextEntry()) != null) { if (entry.isDirectory()) { File f = Paths.get(destinationAbsolutePath, entry.getName()).toFile(); f.mkdirs(); } else { Path fileDestinationPath = Paths.get(destinationAbsolutePath, entry.getName()); Files.copy(tarInputStream, fileDestinationPath, StandardCopyOption.REPLACE_EXISTING); } } } }
From source file:azkaban.project.DirectoryFlowLoaderTest.java
private static File decompressTarBZ2(InputStream is) throws IOException { File outputDir = Files.createTempDir(); try (TarArchiveInputStream tais = new TarArchiveInputStream(new BZip2CompressorInputStream(is))) { TarArchiveEntry entry;//from w w w . j a v a 2s . co m while ((entry = tais.getNextTarEntry()) != null) { if (entry.isDirectory()) { continue; } File outputFile = new File(outputDir, entry.getName()); File parent = outputFile.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } try (FileOutputStream os = new FileOutputStream(outputFile)) { IOUtils.copy(tais, os); } } return outputDir; } }
From source file:com.netflix.spinnaker.clouddriver.appengine.artifacts.StorageUtils.java
public static void untarStreamToPath(InputStream inputStream, String basePath) throws IOException { class DirectoryTimestamp { public DirectoryTimestamp(File d, long m) { directory = d;//from w w w . ja va 2 s. c o m millis = m; } public File directory; public long millis; } ; // Directories come in hierarchical order within the stream, but // we need to set their timestamps after their children have been written. Stack<DirectoryTimestamp> directoryStack = new Stack<DirectoryTimestamp>(); File baseDirectory = new File(basePath); baseDirectory.mkdir(); TarArchiveInputStream tarStream = new TarArchiveInputStream(inputStream); for (TarArchiveEntry entry = tarStream.getNextTarEntry(); entry != null; entry = tarStream .getNextTarEntry()) { File target = new File(baseDirectory, entry.getName()); if (entry.isDirectory()) { directoryStack.push(new DirectoryTimestamp(target, entry.getModTime().getTime())); continue; } writeStreamToFile(tarStream, target); target.setLastModified(entry.getModTime().getTime()); } while (!directoryStack.empty()) { DirectoryTimestamp info = directoryStack.pop(); info.directory.setLastModified(info.millis); } tarStream.close(); }
From source file:de.dentrassi.pm.utils.deb.Packages.java
public static Map<String, String> parseControlFile(final File packageFile) throws IOException, ParserException { try (final ArArchiveInputStream in = new ArArchiveInputStream(new FileInputStream(packageFile))) { ArchiveEntry ar;//from ww w .j ava2 s.com while ((ar = in.getNextEntry()) != null) { if (!ar.getName().equals("control.tar.gz")) { continue; } try (final TarArchiveInputStream inputStream = new TarArchiveInputStream(new GZIPInputStream(in))) { TarArchiveEntry te; while ((te = inputStream.getNextTarEntry()) != null) { String name = te.getName(); if (name.startsWith("./")) { name = name.substring(2); } if (!name.equals("control")) { continue; } return parseControlFile(inputStream); } } } } return null; }
From source file:com.amazonaws.codepipeline.jenkinsplugin.ExtractionTools.java
private static void extractTar(final File source, final File destination) throws IOException { try (final ArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream( new FileInputStream(source))) { extractArchive(destination, tarArchiveInputStream); }//www . ja va2 s . co m }
From source file:edu.jhu.hlt.acute.iterators.tar.TarArchiveEntryByteIterator.java
/** * Wrap an {@link InputStream}.//from w w w .ja v a 2 s.c o m * * @throws IOException if there are issues with the underlying archive (it has no * files, for example) */ public TarArchiveEntryByteIterator(InputStream is) throws IOException { this.tis = new TarArchiveInputStream(is); // Prepare next entry. this.tis.getNextTarEntry(); }
From source file:deployer.publishers.TarFileChecker.java
public void check(InputStream is) throws Exception { GZIPInputStream gzis = new GZIPInputStream(is); TarArchiveInputStream tarIs = new TarArchiveInputStream(gzis); check(tarIs);//from ww w . j av a 2 s . co m }
From source file:com.comcast.cdn.traffic_control.traffic_router.neustar.data.TarExtractor.java
public boolean extractTo(File directory, InputStream inputStream) { try (TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(inputStream)) { TarArchiveEntry tarArchiveEntry; while ((tarArchiveEntry = tarArchiveInputStream.getNextTarEntry()) != null) { if (tarArchiveEntry.isDirectory()) { continue; }/*from ww w .ja va 2 s. com*/ File file = new File(directory, tarArchiveEntry.getName()); LOGGER.info("Extracting Tarfile entry " + tarArchiveEntry.getName() + " to temporary location " + file.getAbsolutePath()); if (!file.exists() && !file.createNewFile()) { LOGGER.warn("Failed to extract file to " + file.getAbsolutePath() + ", cannot create file, check permissions of " + directory.getAbsolutePath()); return false; } copyInputStreamToFile(tarArchiveInputStream, file); } } catch (IOException e) { LOGGER.error("Failed extracting tar archive to directory " + directory.getAbsolutePath() + " : " + e.getMessage()); return false; } return true; }
From source file:de.flapdoodle.embed.process.extract.TxzExtractor.java
protected ArchiveWrapper archiveStream(File source) throws IOException { FileInputStream fin = new FileInputStream(source); BufferedInputStream in = new BufferedInputStream(fin); XZCompressorInputStream gzIn = new XZCompressorInputStream(in); TarArchiveInputStream tarIn = new TarArchiveInputStream(gzIn); return new TarArchiveWrapper(tarIn); }