List of usage examples for java.util.zip ZipFile ZipFile
public ZipFile(File file) throws ZipException, IOException
From source file:com.espirit.moddev.basicworkflowsTestIT.java
/** * Check if FSM is valid/* w w w.j av a 2 s.co m*/ */ @Test public void testisFSMValid() { try { File directory = new File("target"); Collection files = FileUtils.listFiles(directory, new WildcardFileFilter("*.fsm"), null); assertTrue("FSM doesn't contain any files", files.iterator().hasNext()); if (files.iterator().hasNext()) { ZipFile _fsmZip = new ZipFile((File) files.iterator().next()); ZipEntry fsmEntry = _fsmZip.getEntry(MODULE_DESCRIPTOR); assertNotNull("Couldn't find module descriptor (module.xml) in fsm file", fsmEntry); } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.formkiq.core.util.Zips.java
/** * Is Zip file valid.// w w w . ja v a2s .co m * @param file {@link File} * @return boolean * @throws IOException IOException */ public static boolean isValid(final File file) throws IOException { ZipFile zipfile = new ZipFile(file); IOUtils.closeQuietly(zipfile); return true; }
From source file:com.dibsyhex.apkdissector.ZipReader.java
public void getZipEntries(String name) { try {//ww w . java 2 s. c om File file = new File(name); ZipFile zipFile = new ZipFile(file); Enumeration<? extends ZipEntry> enumeration = zipFile.entries(); System.out.println("Listing Entries in the apkfile"); response.displayLog("Listing Entries in the apkfile"); while (enumeration.hasMoreElements()) { Object key = enumeration.nextElement(); //String s=key.toString()+":"+zipFile.getEntry(key.toString()); String s = zipFile.getEntry(key.toString()).toString(); System.out.println(" " + s); response.displayLog(s); } zipFile.close(); } catch (Exception e) { System.out.println(e.toString()); response.displayError(e.toString()); } }
From source file:Zip.java
/** * Reads a Zip file, iterating through each entry and dumping the contents * to the console./*from w w w . ja va 2s . c o m*/ */ public static void readZipFile(String fileName) { ZipFile zipFile = null; try { // ZipFile offers an Enumeration of all the files in the Zip file zipFile = new ZipFile(fileName); for (Enumeration e = zipFile.entries(); e.hasMoreElements();) { ZipEntry zipEntry = (ZipEntry) e.nextElement(); System.out.println(zipEntry.getName() + " contains:"); // use BufferedReader to get one line at a time BufferedReader zipReader = new BufferedReader( new InputStreamReader(zipFile.getInputStream(zipEntry))); while (zipReader.ready()) { System.out.println(zipReader.readLine()); } zipReader.close(); } } catch (IOException ioe) { System.out.println("An IOException occurred: " + ioe.getMessage()); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException ioe) { } } } }
From source file:JarResource.java
private List<String> load(File jarFile) throws IOException { List<String> jarContents = new ArrayList<String>(); try {/*from ww w.j a v a 2 s. c om*/ ZipFile zf = new ZipFile(jarFile); for (Enumeration e = zf.entries(); e.hasMoreElements();) { ZipEntry ze = (ZipEntry) e.nextElement(); if (ze.isDirectory()) { continue; } jarContents.add(ze.getName()); } } catch (NullPointerException e) { System.out.println("done."); } catch (ZipException ze) { ze.printStackTrace(); } return jarContents; }
From source file:de.marza.firstspirit.modules.logging.fsm.FsmIT.java
/** * Check if FSM is valid.// w w w .j a va2 s .co m * * @throws Exception the exception */ @Test public void testisFSMValid() throws Exception { final File directory = new File("target"); final Collection<File> files = FileUtils.listFiles(directory, new WildcardFileFilter("*.fsm"), null); final Iterator<File> iterator = files.iterator(); assertTrue("FSM doesn't contain any files", iterator.hasNext()); if (iterator.hasNext()) { try (final ZipFile _fsmZip = new ZipFile(iterator.next())) { final ZipEntry license = _fsmZip.getEntry("LICENSE"); errors.checkThat("Couldn't find module descriptor (module.xml) in fsm file", license, is(notNullValue())); final ZipEntry moduleXML = _fsmZip.getEntry(MODULE_DESCRIPTOR); errors.checkThat("Couldn't find module descriptor (module.xml) in fsm file", moduleXML, is(notNullValue())); final ZipEntry consoleLib = _fsmZip .getEntry("lib/console-" + pomProperties.getProperty("version") + ".jar"); errors.checkThat("Couldn't find lib in fsm file", consoleLib, is(notNullValue())); final ZipEntry toolbarLib = _fsmZip .getEntry("lib/toolbar-" + pomProperties.getProperty("version") + ".jar"); errors.checkThat("Couldn't find lib in fsm file", toolbarLib, is(notNullValue())); } } }
From source file:com.termmed.utils.ResourceUtils.java
/** * Gets the resources from jar file./*from ww w.jav a 2 s .c o m*/ * * @param file the file * @param pattern the pattern * @return the resources from jar file */ private static Collection<String> getResourcesFromJarFile(final File file, final Pattern pattern) { final ArrayList<String> retval = new ArrayList<String>(); ZipFile zf; try { zf = new ZipFile(file); } catch (final ZipException e) { throw new Error(e); } catch (final IOException e) { throw new Error(e); } final Enumeration e = zf.entries(); while (e.hasMoreElements()) { final ZipEntry ze = (ZipEntry) e.nextElement(); final String fileName = ze.getName(); final boolean accept = pattern.matcher(fileName).matches(); if (accept) { retval.add(fileName); } } try { zf.close(); } catch (final IOException e1) { throw new Error(e1); } return retval; }
From source file:dk.deck.resolver.util.ZipUtils.java
public void unzipArchive(File archive, File outputDir) { try {/*from w ww . j a v a2 s.c om*/ ZipFile zipfile = new ZipFile(archive); for (Enumeration e = zipfile.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); unzipEntry(zipfile, entry, outputDir); } zipfile.close(); } catch (Exception e) { log.error("Error while extracting file " + archive, e); } }
From source file:be.fedict.eid.pkira.blm.model.contracts.CertificateTest.java
@Test public void testGetCertificateZip() throws Exception { CertificateChainCertificate certificateChainCertificate2 = new CertificateChainCertificate(); certificateChainCertificate2.setCertificateData("chain2\n"); CertificateChainCertificate certificateChainCertificate1 = new CertificateChainCertificate(); certificateChainCertificate1.setCertificateData("chain1\n"); certificateChainCertificate1.setIssuer(certificateChainCertificate2); Certificate certificate = new Certificate(); certificate.setX509("x509test\n"); certificate.setCertificateChainCertificate(certificateChainCertificate1); File file = new File("target/testcertificate.zip"); FileUtils.writeByteArrayToFile(file, certificate.getCertificateZip()); ZipFile zipFile = new ZipFile(file); validateNextZipEntry(zipFile, "certificate.crt", "x509test\n"); validateNextZipEntry(zipFile, "chain1.crt", "chain1\n"); validateNextZipEntry(zipFile, "chain2.crt", "chain2\n"); }
From source file:com.replaymod.replaystudio.launcher.ReverseLauncher.java
public void launch(CommandLine cmd) throws Exception { ZipFile file = new ZipFile(cmd.getArgs()[0]); ZipEntry entry = file.getEntry("recording.tmcpr"); if (entry == null) { throw new IOException("Input file is not a valid replay file."); }/* ww w.jav a2s . com*/ long size = entry.getSize(); if (size == -1) { throw new IOException("Uncompressed size of recording.tmcpr not set."); } InputStream from = file.getInputStream(entry); RandomAccessFile to = new RandomAccessFile(cmd.getArgs()[1], "rw"); to.setLength(size); int nRead; long pos = size; byte[] buffer = new byte[8192]; long lastUpdate = -1; while (true) { long pct = 100 - pos * 100 / size; if (lastUpdate != pct) { System.out.print("Reversing " + size + " bytes... " + pct + "%\r"); lastUpdate = pct; } int next = readInt(from); int length = readInt(from); if (next == -1 || length == -1) { break; // reached end of stream } // Increase buffer if necessary if (length + 8 > buffer.length) { buffer = new byte[length + 8]; } buffer[0] = (byte) ((next >>> 24) & 0xFF); buffer[1] = (byte) ((next >>> 16) & 0xFF); buffer[2] = (byte) ((next >>> 8) & 0xFF); buffer[3] = (byte) (next & 0xFF); buffer[4] = (byte) ((length >>> 24) & 0xFF); buffer[5] = (byte) ((length >>> 16) & 0xFF); buffer[6] = (byte) ((length >>> 8) & 0xFF); buffer[7] = (byte) (length & 0xFF); nRead = 0; while (nRead < length) { nRead += from.read(buffer, 8 + nRead, length - nRead); } pos -= length + 8; to.seek(pos); to.write(buffer, 0, length + 8); } from.close(); to.close(); System.out.println("\nDone!"); }