List of usage examples for org.apache.commons.compress.archivers ArchiveEntry getName
public String getName();
From source file:org.mcisb.subliminal.SubliminalUtils.java
/** * /* ww w . j a v a 2 s. c om*/ * @param url * @param destinationDirectory * @throws IOException */ public static void untar(final URL url, final File destinationDirectory) throws IOException { if (!destinationDirectory.exists()) { if (!destinationDirectory.mkdir()) { throw new IOException(); } } TarArchiveInputStream is = null; try { is = new TarArchiveInputStream(new GZIPInputStream(url.openStream())); ArchiveEntry tarEntry = null; while ((tarEntry = is.getNextEntry()) != null) { final File destination = new File(destinationDirectory, tarEntry.getName()); if (tarEntry.isDirectory()) { if (!destination.mkdir()) { // Take no action. // throw new IOException(); } } else { try (final OutputStream os = new FileOutputStream(destination)) { new StreamReader(is, os).read(); } } } } catch (IOException e) { if (!destinationDirectory.delete()) { throw new IOException(); } throw e; } finally { if (is != null) { is.close(); } } }
From source file:org.mcisb.util.io.TarUtils.java
/** * //ww w .ja v a 2 s .c om * @param tarInputStream * @param destinationDirectory * @throws IOException */ public static void untar(final InputStream tarInputStream, final File destinationDirectory) throws IOException { if (!destinationDirectory.exists()) { if (!destinationDirectory.mkdir()) { throw new IOException(); } } TarArchiveInputStream is = null; try { is = new TarArchiveInputStream(new GZIPInputStream(tarInputStream)); ArchiveEntry tarEntry = null; while ((tarEntry = is.getNextEntry()) != null) { final File destination = new File(destinationDirectory, tarEntry.getName()); if (tarEntry.isDirectory()) { if (!destination.mkdir()) { // Take no action. // throw new IOException(); } } else { try (final OutputStream os = new FileOutputStream(destination)) { new StreamReader(is, os).read(); } } } } catch (IOException e) { if (!destinationDirectory.delete()) { throw new IOException(); } throw e; } finally { if (is != null) { is.close(); } } }
From source file:org.metaservice.core.file.archives.ArchiveExtractionProcessor.java
private void processArchiveExtraction(ArchiveInputStream archiveInputStream, URI uri, RepositoryConnection repositoryConnection) throws IOException, FileProcessingException, RepositoryException { ValueFactory valueFactory = repositoryConnection.getValueFactory(); ArchiveEntry archiveEntry; while ((archiveEntry = archiveInputStream.getNextEntry()) != null) { //ignore directories if (archiveEntry.isDirectory()) { continue; }/* w w w . j a v a 2s.com*/ FileIdentifier identifier = FileUriUtils.storeFile(archiveInputStream); URI entryURI = valueFactory.createURI(uri.toString() + "/" + archiveEntry.getName()); FileRetrievalProcessor.addFile(repositoryConnection, identifier); URI contentURI = identifier.getUri(); repositoryConnection.add(contentURI, DCTERMS.IS_PART_OF, uri); repositoryConnection.add(entryURI, DCTERMS.IS_FORMAT_OF, contentURI); } }
From source file:org.mitre.xtext.converters.ArchiveNavigator.java
/** */ private File saveArchiveEntry(ArchiveEntry E, InputStream archiveio, String root) throws IOException { File target = new File(root + File.separator + E.getName()); target.getParentFile().mkdirs();// ww w . j ava 2 s.c om if (log.isDebugEnabled()) { log.debug("File = " + E.getName()); } OutputStream output = new FileOutputStream(target); IOUtils.copy(archiveio, output); output.close(); return target; }
From source file:org.mitre.xtext.converters.ArchiveNavigator.java
private boolean filterEntry(ArchiveEntry E) { if (E.isDirectory()) { return true; }//from w w w . j ava 2 s . co m if (filter.filterOutFile(E.getName())) { return true; } return false; }
From source file:org.ng200.openolympus.controller.task.TaskFilesystemManipulatingController.java
@PreAuthorize(SecurityExpressionConstants.IS_ADMIN) private void extractZipFile(final InputStream zipFile, final Path destination) throws Exception { try (ArchiveInputStream input = new ArchiveStreamFactory() .createArchiveInputStream(new BufferedInputStream(zipFile))) { ArchiveEntry entry; while ((entry = input.getNextEntry()) != null) { final Path dest = destination.resolve(entry.getName()); if (entry.isDirectory()) { FileAccess.createDirectories(dest); } else { FileAccess.createDirectories(dest.getParent()); FileAccess.createFile(dest); Files.copy(input, dest, StandardCopyOption.REPLACE_EXISTING); }/*from w ww. jav a2 s. co m*/ } } }
From source file:org.obm.push.arquillian.ManagedTomcatInstaller.java
private static void uncompressTarFile(File parent, File inputFile) throws FileNotFoundException, IOException, ArchiveException { FileInputStream inputStream = new FileInputStream(inputFile); ArchiveInputStream archiveInputStream = null; try {/* ww w.ja v a 2s. c o m*/ archiveInputStream = new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, inputStream); ArchiveEntry entry = null; while ((entry = archiveInputStream.getNextEntry()) != null) { File outputFile = new File(parent, entry.getName()); if (entry.isDirectory()) { if (!outputFile.exists()) { if (!outputFile.mkdir()) { throw new IOException( String.format("Unable to create directory %s", outputFile.getAbsolutePath())); } } } else { FileOutputStream outputFileStream = new FileOutputStream(outputFile); try { IOUtils.copy(archiveInputStream, outputFileStream); } finally { outputFileStream.close(); } } } } finally { try { if (archiveInputStream != null) { archiveInputStream.close(); } } finally { inputStream.close(); } } }
From source file:org.openengsb.openengsbplugin.Provision.java
private void extract(ArchiveInputStream is, File targetDir) throws IOException { try {//w w w . j a va 2 s .com if (!targetDir.exists()) { targetDir.mkdirs(); ArchiveEntry entry = is.getNextEntry(); while (entry != null) { String name = entry.getName(); name = name.substring(name.indexOf("/") + 1); File file = new File(targetDir, name); if (entry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); OutputStream os = new FileOutputStream(file); try { IOUtils.copy(is, os); } finally { IOUtils.closeQuietly(os); } } entry = is.getNextEntry(); } } } finally { is.close(); } }
From source file:org.opensextant.xtext.collectors.ArchiveNavigator.java
/** */ private File saveArchiveEntry(ArchiveEntry E, InputStream archiveio, String root) throws IOException { // Note: using native OS file path is fine here. As long as you do not // try any string mechanics on paths. ///*from w ww . ja v a2s .c o m*/ String targetPath = FilenameUtils.concat(root, E.getName()); if (targetPath == null) { throw new IOException("Invalid archive entry target for " + E.getName()); } File target = new File(targetPath); if (target.exists() && !overwrite) { return target; } target.getParentFile().mkdirs(); log.debug("ARCHIVE_ENTRY={}", E.getName()); OutputStream output = null; try { output = new FileOutputStream(target); IOUtils.copy(archiveio, output); } finally { output.close(); } return target; }
From source file:org.owasp.dependencycheck.analyzer.ArchiveAnalyzer.java
/** * Extracts files from an archive./*from w w w . ja v a 2 s. c o m*/ * * @param input the archive to extract files from * @param destination the location to write the files too * @param engine the dependency-check engine * @throws ArchiveExtractionException thrown if there is an exception extracting files from the archive */ private void extractArchive(ArchiveInputStream input, File destination, Engine engine) throws ArchiveExtractionException { ArchiveEntry entry; try { while ((entry = input.getNextEntry()) != null) { if (entry.isDirectory()) { final File d = new File(destination, entry.getName()); if (!d.exists()) { if (!d.mkdirs()) { final String msg = String.format("Unable to create directory '%s'.", d.getAbsolutePath()); throw new AnalysisException(msg); } } } else { final File file = new File(destination, entry.getName()); final String ext = FileUtils.getFileExtension(file.getName()); if (engine.supportsExtension(ext)) { BufferedOutputStream bos = null; FileOutputStream fos; try { final File parent = file.getParentFile(); if (!parent.isDirectory()) { if (!parent.mkdirs()) { final String msg = String.format("Unable to build directory '%s'.", parent.getAbsolutePath()); throw new AnalysisException(msg); } } fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos, BUFFER_SIZE); int count; final byte data[] = new byte[BUFFER_SIZE]; while ((count = input.read(data, 0, BUFFER_SIZE)) != -1) { bos.write(data, 0, count); } bos.flush(); } catch (FileNotFoundException ex) { LOGGER.log(Level.FINE, null, ex); final String msg = String.format("Unable to find file '%s'.", file.getName()); throw new AnalysisException(msg, ex); } catch (IOException ex) { LOGGER.log(Level.FINE, null, ex); final String msg = String.format("IO Exception while parsing file '%s'.", file.getName()); throw new AnalysisException(msg, ex); } finally { if (bos != null) { try { bos.close(); } catch (IOException ex) { LOGGER.log(Level.FINEST, null, ex); } } } } } } } catch (IOException ex) { throw new ArchiveExtractionException(ex); } catch (Throwable ex) { throw new ArchiveExtractionException(ex); } finally { if (input != null) { try { input.close(); } catch (IOException ex) { LOGGER.log(Level.FINEST, null, ex); } } } }