List of usage examples for org.apache.commons.compress.archivers.zip ZipFile ZipFile
public ZipFile(String name) throws IOException
From source file:com.oculusinfo.binning.io.impl.ZipResourcePyramidSource.java
public ZipResourcePyramidSource(String zipFilePath, String tileExtension) { try {//from w w w.j av a 2 s . c o m _tileSetArchive = new ZipFile(zipFilePath); _tileExtension = tileExtension; } catch (IOException e) { LOGGER.warn("Could not create zip file for " + zipFilePath, e); } }
From source file:com.nabla.wapp.report.server.ReportZipFile.java
public ReportZipFile(final InputStream zip) throws InternalErrorException { try {/*w w w . ja va2 s . c o m*/ zipFile = File.createTempFile("wapp_report", null); } catch (IOException e) { if (log.isErrorEnabled()) log.error("fail to create temporary file to hold zip stream"); throw new InternalErrorException(Util.formatInternalErrorDescription(e)); } try { final FileOutputStream out = new FileOutputStream(zipFile); IOUtils.copy(zip, out); out.close(); } catch (Throwable e) { zipFile.delete(); throw new InternalErrorException(Util.formatInternalErrorDescription(e)); } try { impl = new ZipFile(zipFile); } catch (IOException e) { if (log.isErrorEnabled()) log.error("fail to open temporary zip file"); zipFile.delete(); throw new InternalErrorException(Util.formatInternalErrorDescription(e)); } }
From source file:com.nit.libanki.importer.Anki2Importer.java
public Anki2Importer(Collection col, String file, DeckTask.ProgressCallback progressCallback) throws IOException { mCol = col;//w w w . j a va 2s . com mZip = new ZipFile(new File(file)); mTotal = 0; mLog = new ArrayList<String>(); mProgress = progressCallback; if (mProgress != null) { mResources = mProgress.getResources(); } nameToNum = new HashMap<String, String>(); }
From source file:com.android.tradefed.util.ZipUtil2.java
/** * Extract a zip file to a temp directory prepended with a string * * @param zipFile the zip file to extract * @param nameHint a prefix for the temp directory * @return a {@link File} pointing to the temp directory *//*from w w w .j a v a 2 s . c o m*/ public static File extractZipToTemp(File zipFile, String nameHint) throws IOException { File localRootDir = FileUtil.createTempDir(nameHint); try (ZipFile zip = new ZipFile(zipFile)) { extractZip(zip, localRootDir); return localRootDir; } catch (IOException e) { // clean tmp file since we couldn't extract. FileUtil.recursiveDelete(localRootDir); throw e; } }
From source file:com.yahoo.parsec.gradle.ParsecInitTask.java
/** * Extract Parsec Rdl Generator.//from w ww .j a v a 2 s . co m * * @param rdlBinSuffix rdl bin suffix * @param generators the generator list * @throws IOException IOException */ void extractParsecRdlGenerator(final String rdlBinSuffix, final List<String> generators) throws IOException { final File file = fileUtils.getFileFromResource("/rdl-gen/rdl-gen.zip"); for (String g : generators) { String generatorBinary = PathUtils.RDL_GEN_PARSEC_PREFIX + g; try (ZipFile zipFile = new ZipFile(file); InputStream inputStream = zipFile .getInputStream(zipFile.getEntry(generatorBinary + "-" + rdlBinSuffix))) { fileUtils.writeResourceAsExecutable(inputStream, pathUtils.getBinPath() + "/" + generatorBinary); } } }
From source file:fr.acxio.tools.agia.tasks.ZipFilesTaskletTest.java
@Test public void testZipFile() throws Exception { String aTargetFilename = "target/Z0-input.zip"; ZipFilesTasklet aTasklet = new ZipFilesTasklet(); aTasklet.setSourceBaseDirectory(new FileSystemResource("src/test/resources/testFiles/")); FileSystemResourcesFactory aSourceFactory = new FileSystemResourcesFactory(); aSourceFactory.setPattern("file:src/test/resources/testFiles/input.csv"); aTasklet.setSourceFactory(aSourceFactory); ExpressionResourceFactory aDestinationFactory = new ExpressionResourceFactory(); aDestinationFactory.setExpression(aTargetFilename); aTasklet.setDestinationFactory(aDestinationFactory); assertFalse(new File(aTargetFilename).exists()); StepContribution aStepContribution = mock(StepContribution.class); assertEquals(RepeatStatus.FINISHED, aTasklet.execute(aStepContribution, null)); verify(aStepContribution, times(1)).incrementReadCount(); verify(aStepContribution, times(1)).incrementWriteCount(1); assertTrue(new File(aTargetFilename).exists()); ZipFile aZipFile = new ZipFile(new File(aTargetFilename)); Enumeration<ZipArchiveEntry> aEntries = aZipFile.getEntries(); assertTrue(aEntries.hasMoreElements()); assertEquals("input.csv", aEntries.nextElement().getName()); assertFalse(aEntries.hasMoreElements()); aZipFile.close();//w w w.j a v a 2 s. co m }
From source file:io.wcm.maven.plugins.contentpackage.unpacker.ContentUnpacker.java
/** * Unpacks file//from w ww .ja v a 2s .co m * @param file File * @param outputDirectory Output directory * @throws MojoExecutionException */ public void unpack(File file, File outputDirectory) throws MojoExecutionException { ZipFile zipFile = null; try { zipFile = new ZipFile(file); Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry entry = entries.nextElement(); if (!exclude(entry.getName(), excludeFiles)) { unpackEntry(zipFile, entry, outputDirectory); } } } catch (IOException ex) { throw new MojoExecutionException("Error reading content package " + file.getAbsolutePath(), ex); } finally { IOUtils.closeQuietly(zipFile); } }
From source file:com.android.tradefed.testtype.suite.TfSuiteRunner.java
/** * Internal load configuration. Load configuration, expand sub suite runners and track cycle * inclusion to prevent infinite recursion. * * @param parentConfig the name of the config being loaded. * @param graph the directed graph tracking inclusion. * @return a map of module name and the configuration associated. *///w w w. j ava 2s. c o m private LinkedHashMap<String, IConfiguration> loadTests(String parentConfig, DirectedGraph<String> graph) { LinkedHashMap<String, IConfiguration> configMap = new LinkedHashMap<String, IConfiguration>(); IConfigurationFactory configFactory = ConfigurationFactory.getInstance(); // TODO: Do a better job searching for configs. // We do not load config from environment, they should be inside the testsDir of the build // info. List<String> configs = configFactory.getConfigList(mSuitePrefix, false); if (getBuildInfo() instanceof IDeviceBuildInfo) { IDeviceBuildInfo deviceBuildInfo = (IDeviceBuildInfo) getBuildInfo(); File testsDir = deviceBuildInfo.getTestsDir(); if (testsDir != null) { if (mAdditionalTestsZip != null) { CLog.d("Extract general-tests.zip (%s) to tests directory.", mAdditionalTestsZip); ZipFile zip = null; try { zip = new ZipFile(mAdditionalTestsZip); ZipUtil2.extractZip(zip, testsDir); } catch (IOException e) { RuntimeException runtimeException = new RuntimeException( String.format("IO error (%s) when unzipping general-tests.zip", e.toString()), e); throw runtimeException; } finally { StreamUtil.close(zip); } } CLog.d("Loading extra test configs from the tests directory: %s", testsDir.getAbsolutePath()); List<File> extraTestCasesDirs = Arrays.asList(testsDir); configs.addAll(ConfigurationUtil.getConfigNamesFromDirs(mSuitePrefix, extraTestCasesDirs)); } } // Sort configs to ensure they are always evaluated and added in the same order. Collections.sort(configs); for (String configName : configs) { try { IConfiguration testConfig = configFactory.createConfigurationFromArgs(new String[] { configName }); if (testConfig.getConfigurationDescription().getSuiteTags().contains(mSuiteTag)) { // In case some sub-config are suite too, we expand them to avoid weirdness // of modules inside modules. if (parentConfig != null) { graph.addEdge(parentConfig, configName); if (!graph.isDag()) { CLog.e("%s", graph); throw new RuntimeException(String.format( "Circular configuration detected: %s has been included " + "several times.", configName)); } } LinkedHashMap<String, IConfiguration> expandedConfig = expandTestSuites(configName, testConfig, graph); configMap.putAll(expandedConfig); } } catch (ConfigurationException | NoClassDefFoundError e) { // Do not print the stack it's too verbose. CLog.e("Configuration '%s' cannot be loaded, ignoring.", configName); } } return configMap; }
From source file:com.synopsys.integration.util.CommonZipExpander.java
private void expandUnknownFile(File unknownFile, File targetExpansionDirectory) throws IOException, IntegrationException, ArchiveException { String format;/*from w w w . ja v a2s. c o m*/ // we need to use an InputStream where inputStream.markSupported() == true try (InputStream i = new BufferedInputStream(Files.newInputStream(unknownFile.toPath()))) { format = new ArchiveStreamFactory().detect(i); } beforeExpansion(unknownFile, targetExpansionDirectory); // in the case of zip files, commons-compress creates, but does not close, the ZipFile. To avoid this unclosed resource, we handle it ourselves. try { if (ArchiveStreamFactory.ZIP.equals(format)) { try (ZipFile zipFile = new ZipFile(unknownFile)) { expander.expand(zipFile, targetExpansionDirectory); } } else { expander.expand(unknownFile, targetExpansionDirectory); } } catch (IOException | ArchiveException e) { logger.error("Couldn't extract the archive file - check the file's permissions: " + e.getMessage()); throw e; } afterExpansion(unknownFile, targetExpansionDirectory); }
From source file:com.android.tradefed.util.Bugreport.java
/** * Returns the list of files contained inside the zipped bugreport. Null if it's not a zipped * bugreport.// w w w.j a v a 2s .c om */ public List<String> getListOfFiles() { if (mBugreport == null) { return null; } List<String> list = new ArrayList<>(); if (!mIsZipped) { return null; } try (ZipFile zipBugreport = new ZipFile(mBugreport)) { for (ZipArchiveEntry entry : Collections.list(zipBugreport.getEntries())) { list.add(entry.getName()); } } catch (IOException e) { CLog.e("Error reading the list of files in the bugreport"); CLog.e(e); } return list; }