List of usage examples for java.util.zip ZipFile getEntry
public ZipEntry getEntry(String name)
From source file:org.pentaho.osgi.platform.webjars.WebjarsURLConnectionTest.java
private void verifyMinified(ZipFile zipInputStream, String expectedPath, String file) throws IOException { ZipEntry entry = zipInputStream.getEntry("META-INF/resources/dist-gen/" + file); assertNotNull(entry);//from w w w. java2s. co m String minFile = IOUtils.toString(zipInputStream.getInputStream(entry), "UTF-8"); entry = zipInputStream.getEntry("META-INF/resources/webjars/" + expectedPath + "/" + file); assertNotNull(entry); String srcFile = IOUtils.toString(zipInputStream.getInputStream(entry), "UTF-8"); assertNotEquals(minFile, srcFile); }
From source file:org.pentaho.osgi.platform.webjars.WebjarsURLConnectionTest.java
private void verifyNotMinified(ZipFile zipInputStream, String expectedPath, String file) throws IOException { ZipEntry entry = zipInputStream.getEntry("META-INF/resources/dist-gen/" + file); assertNotNull(entry);/*from w ww . j a va2 s . c om*/ String minFile = IOUtils.toString(zipInputStream.getInputStream(entry), "UTF-8"); entry = zipInputStream.getEntry("META-INF/resources/webjars/" + expectedPath + "/" + file); assertNotNull(entry); String srcFile = IOUtils.toString(zipInputStream.getInputStream(entry), "UTF-8"); assertEquals(minFile, srcFile); }
From source file:com.denizensoft.appcompatlib.AppActivity.java
@Override public Date packageBuildTimestamp() { try {//from w ww . j a v a2 s . c o m ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), 0); ZipFile zf = new ZipFile(ai.sourceDir); ZipEntry ze = zf.getEntry("classes.dex"); return new Date(ze.getTime()); } catch (PackageManager.NameNotFoundException e) { appFatalErrorHook("App", e.getMessage()); } catch (IOException e) { appFatalErrorHook("App", e.getMessage()); } return null; }
From source file:com.streamsets.datacollector.bundles.TestSupportBundleManager.java
@Test public void testSimpleStatsBundleCreation() throws Exception { ZipFile bundle = zipFile(ImmutableList.of(SimpleGenerator.class.getSimpleName()), BundleType.STATS); ZipEntry entry;//from w w w. ja v a 2 s . com // Make sure that some files are actually missing entry = bundle.getEntry("metadata.properties"); assertNull(entry); // Check we have expected files entry = bundle.getEntry("generators.properties"); assertNotNull(entry); entry = bundle.getEntry("failed_generators.properties"); assertNotNull(entry); entry = bundle.getEntry("com.streamsets.datacollector.bundles.content.SimpleGenerator/file.txt"); assertNotNull(entry); }
From source file:org.fao.geonet.api.mapservers.GeoFile.java
/** * Returns the names of the vector layers (Shapefiles) in the geographic file. * * @param onlyOneFileAllowed Return exception if more than one shapefile found * @return a collection of layer names//from w ww. j a va 2 s . c o m * @throws IllegalArgumentException If more than on shapefile is found and onlyOneFileAllowed is * true or if Shapefile name is not equal to zip file base * name */ public Collection<String> getVectorLayers(final boolean onlyOneFileAllowed) throws IOException { final LinkedList<String> layers = new LinkedList<String>(); if (zipFile != null) { for (Path path : zipFile.getRootDirectories()) { Files.walkFileTree(path, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { String fileName = file.getFileName().toString(); if (fileIsShp(fileName)) { String base = getBase(fileName); if (onlyOneFileAllowed) { if (layers.size() > 1) throw new IllegalArgumentException("Only one shapefile per zip is allowed. " + layers.size() + " shapefiles found."); if (base.equals(getBase(fileName))) { layers.add(base); } else throw new IllegalArgumentException("Shapefile name (" + base + ") is not equal to ZIP file name (" + file.getFileName() + ")."); } else { layers.add(base); } } if (fileIsSld(fileName)) { _containsSld = true; _sldBody = fileName; } return FileVisitResult.CONTINUE; } }); } if (_containsSld) { ZipFile zf = new ZipFile(new File(this.file.toString())); InputStream is = zf.getInputStream(zf.getEntry(_sldBody)); BufferedReader br = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); String line; _sldBody = ""; while ((line = br.readLine()) != null) { _sldBody += line; } br.close(); is.close(); zf.close(); } } return layers; }
From source file:com.l2jfree.gameserver.util.JarClassLoader.java
private byte[] loadClassData(String name) throws IOException { byte[] classData = null; for (String jarFile : _jars) { ZipFile zipFile = null; DataInputStream zipStream = null; try {/*w w w . j av a2 s .c o m*/ File file = new File(jarFile); zipFile = new ZipFile(file); String fileName = name.replace('.', '/') + ".class"; ZipEntry entry = zipFile.getEntry(fileName); if (entry == null) continue; classData = new byte[(int) entry.getSize()]; zipStream = new DataInputStream(zipFile.getInputStream(entry)); zipStream.readFully(classData, 0, (int) entry.getSize()); break; } catch (IOException e) { _log.warn(jarFile + ":", e); continue; } finally { try { if (zipFile != null) zipFile.close(); } catch (Exception e) { _log.warn("", e); } try { if (zipStream != null) zipStream.close(); } catch (Exception e) { _log.warn("", e); } } } if (classData == null) throw new IOException("class not found in " + _jars); return classData; }
From source file:org.pentaho.webpackage.deployer.archive.impl.UrlTransformer.java
boolean canHandleZipFile(File file) { ZipFile zipFile = null; try {// w ww .j a v a 2 s. co m zipFile = new ZipFile(file); // exclude real jar files // (we only accept the jar extension because of exploded bundles (jardir)) if (zipFile.getEntry("META-INF/MANIFEST.MF") != null) { return false; } ZipInputStream zipInputStream = null; try { zipInputStream = new ZipInputStream(new FileInputStream(file)); ZipEntry entry; while ((entry = zipInputStream.getNextEntry()) != null) { final String name = FilenameUtils.getName(entry.getName()); if (name.equals(WebPackageURLConnection.PACKAGE_JSON)) { return true; } } } catch (IOException ignored) { // Ignore } finally { try { if (zipInputStream != null) { zipInputStream.close(); } } catch (IOException ignored) { // Ignore } } } catch (IOException ignored) { // Ignore } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException ignored) { // Ignore } } } return false; }
From source file:edu.harvard.i2b2.PreProcessFhirSpec.java
public PreProcessFhirSpec() throws IOException, XQueryUtilException { logger.trace("hi"); ArrayList<String> resourceList = new ArrayList<String>(); resourceList.add("Patient".toLowerCase()); resourceList.add("Medication".toLowerCase()); resourceList.add("MedicationStatement".toLowerCase()); resourceList.add("Observation".toLowerCase()); ZipFile zipFile = new ZipFile(Utils.getFilePath("fhir-spec.zip"));// fhir-all-xsd.zip logger.trace("" + zipFile.getName()); Enumeration<? extends ZipEntry> entries = zipFile.entries(); for (String rName : resourceList) { String fName = "site/" + rName + ".profile.xml"; logger.trace("" + zipFile.getEntry(fName)); String fContent = IOUtils.toString(zipFile.getInputStream(zipFile.getEntry(fName))); logger.trace("" + XQueryUtil.processXQuery( "declare default element namespace \"http://hl7.org/fhir\";//searchParam", fContent)); }//from w w w .jav a2 s.c o m /*while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if(!entry.getName().matches(".*\\.html$")) continue; Pattern p = Pattern.compile("^site/([^\\.\\\\]*)\\..*$"); Matcher m = p.matcher(entry.getName()); String rname=""; if (m.matches()) { //logger.trace("" + entry.getName() + "->" + m.group(1)); rname=m.group(1).toLowerCase(); } if (resourceList.contains(rname)) logger.trace(entry.getName()+"->" + rname); // InputStream stream = zipFile.getInputStream(entry); }*/ }
From source file:pl.psnc.synat.wrdz.mdz.integrity.IntegrityVerifierBean.java
@Override public boolean isCorrupted(String identifier, File file) { ZipFile zip = null; try {//from w w w . j av a2 s. co m zip = new ZipFile(file); List<FileHashDto> fileHashes = hashBrowser.getFileHashes(identifier); for (FileHashDto fileHash : fileHashes) { ZipEntry entry = zip.getEntry(fileHash.getObjectFilepath()); if (entry == null) { // file not found in the archive return true; } String calculatedHash; InputStream stream = zip.getInputStream(entry); try { calculatedHash = calculateHash(stream, fileHash.getHashType()); } finally { IOUtils.closeQuietly(stream); } if (!calculatedHash.equals(fileHash.getHashValue())) { return true; } } } catch (ZipException e) { throw new WrdzRuntimeException("Given file is not a valid zip archive", e); } catch (NoSuchAlgorithmException e) { throw new WrdzRuntimeException("Unable to locate appropriate hashing algorithm classes", e); } catch (ObjectNotFoundException e) { throw new WrdzRuntimeException("Digital object not found in ZMD", e); } catch (IOException e) { throw new WrdzRuntimeException("Error while verifying object integrity", e); } finally { if (zip != null) { try { zip.close(); } catch (IOException e) { logger.warn("Could not close the zip file", e); } } } return false; }
From source file:org.python.pydev.core.REF.java
/** * @param f the zip file that should be opened * @param pathInZip the path within the zip file that should be gotten * @param returnType the class that specifies the return type of this method. * If null, it'll return in the fastest possible way available. * Valid options are:/*w ww .ja v a2s .co m*/ * String.class * IDocument.class * FastStringBuffer.class * * @return an object with the contents from a path within a zip file, having the return type * of the object specified by the parameter returnType. */ public static Object getCustomReturnFromZip(File f, String pathInZip, Class<? extends Object> returnType) throws Exception { ZipFile zipFile = new ZipFile(f, ZipFile.OPEN_READ); try { InputStream inputStream = zipFile.getInputStream(zipFile.getEntry(pathInZip)); try { return REF.getStreamContents(inputStream, null, null, returnType); } finally { inputStream.close(); } } finally { zipFile.close(); } }