Java 8 ZipFile - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ZipFile class.

This code example shows how to use the following methods:close, getEntry, getName
	private void validateJdrReportContents(File reportFile) {
	    String reportName = reportFile.getName().replace(".zip","");
 
		ZipFile reportZip = null;
		try { 
			reportZip = new ZipFile(reportFile);
			validateReportEntries(reportZip, reportName);
		} catch (Exception e) {
			throw new RuntimeException("Unable to validate JDR report: " + reportFile.getName(), e);
		} finally { 
			if (reportZip != null) {
				try { 
				    reportZip.close();
				} catch (IOException e) {
				    throw new RuntimeException("Unable to close JDR report: " + reportFile.getName(), e);
				} 
			} 
		} 
	} 
 

9
CodeRank
This code example shows how to use the following methods:getEntry, getInputStream, getName
  } 
 
  @Override 
  public File getSourceFile()
  { 
    return new File(_jarFile.getName());
  } 
 
  @Override 
  public InputStream asInputStream(StringBuilder errorMessageBuilder)
  { 
    InputStream inputStream = null;
    try 
    { 
      ZipEntry zipEntry = _jarFile.getEntry(_pathInJar);
      if (zipEntry != null)
      { 
        inputStream = _jarFile.getInputStream(zipEntry);
      } 
    } 

8
CodeRank
This code example shows how to use the following methods:getName
    public ModuleDefinition getValue() throws IllegalStateException, IllegalArgumentException { 
        return moduleDefinition;
    } 
 
    private static void addResourceRoot(final ModuleSpec.Builder specBuilder, final JarFile file) {
        specBuilder.addResourceRoot(ResourceLoaderSpec.createResourceLoaderSpec(ResourceLoaders.createJarResourceLoader(
                    file.getName(), file)));
    } 
 
} 
8
CodeRank
This code example shows how to use the following methods:close, getEntry
        test( testDir, "install" ).verifyErrorFreeLog();
 
        File swc = new File( testDir, "target/flexmojos-130-1.0-SNAPSHOT.swc" );
        assertThat( swc, FileMatchers.exists() );
 
        ZipFile swcC = new ZipFile( swc );
        try 
        { 
            assertNotNull( swcC.getEntry( "docs/ASDoc_Config.xml" ) );
            assertNotNull( swcC.getEntry( "docs/net.flexmojos.oss.it.xml" ) );
            assertNotNull( swcC.getEntry( "docs/overviews.xml" ) );
            assertNotNull( swcC.getEntry( "docs/packages.dita" ) );
            assertNotNull( swcC.getEntry( "docs/__Global__.xml" ) );
        } 
        finally 
        { 
            swcC.close();
        } 
    } 
} 

7
CodeRank
This code example shows how to use the following methods:getEntry, getInputStream
						"src/test/resources/PackagerValidation/BasicTest"), 
						new ArrayList<File>(0));
		assertNotNull(file);
		assertTrue(file.exists());
 
		final ZipFile zipFile = new ZipFile(file);
 
		final ZipEntry manifestEntry = zipFile.getEntry("META-INF/MANIFEST.MF");
		assertNotNull(manifestEntry);
 
		final InputStream inputStream = zipFile.getInputStream(manifestEntry);
		final Manifest mf = new Manifest();
		mf.read(inputStream);
 
		final String cp = mf.getMainAttributes().getValue("Class-Path");
		assertNotNull(cp);
		assertTrue(cp.contains("dsl.jar"));
      assertTrue(cp.contains("dsl-backwards.jar"));
		assertTrue(cp.contains("usm.jar"));
		inputStream.close();

7
CodeRank
This code example shows how to use the following methods:getEntry, getInputStream
		} 
		return nativeFile.exists() ? nativeFile.getAbsolutePath() : null;
	} 
 
	private InputStream getFromJar (String jarFile, String sharedLibrary) throws IOException {
		ZipFile file = new ZipFile(nativesJar);
		ZipEntry entry = file.getEntry(sharedLibrary);
		return file.getInputStream(entry);
	} 
 
	/** Loads a shared library with the given name for the platform the application is running on. The name should not contain a 
	 * prefix (e.g. 'lib') or suffix (e.g. '.dll). 
	 * @param sharedLibName */ 
	public synchronized void load (String sharedLibName) {
		if (loadedLibraries.contains(sharedLibName)) return;
 
		boolean isWindows = System.getProperty("os.name").contains("Windows");
		boolean isLinux = System.getProperty("os.name").contains("Linux");
		boolean isMac = System.getProperty("os.name").contains("Mac");
		boolean isAndroid = false;
7
CodeRank
This code example shows how to use the following methods:getEntry, getInputStream
	} 
 
	public InputStream openStream() throws IOException {
		// 注:ZipFile与File的设计是不一样的,File相当于C#的FileInfo,只持有信息, 
		// 而ZipFile构造时即打开流,所以每次读取数据时,重新new新的实例,而不作为属性字段持有。 
		ZipFile zipFile = new ZipFile(file);
		return zipFile.getInputStream(zipFile.getEntry(getName()));
	} 
 
	public long getLastModified() { 
		return file.lastModified();
	} 
 
	public long getLength() { 
		try { 
			ZipFile zipFile = new ZipFile(file);
			try { 
				return zipFile.getEntry(getName()).getSize();
			} finally { 
				zipFile.close();
7
CodeRank
This code example shows how to use the following methods:close, getEntry, getInputStream
     * 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 FileUtils.getStreamContents(inputStream, null, null, returnType);
            } finally { 
                inputStream.close();
            } 
        } finally { 
            zipFile.close();
        } 
    } 
 
    /** 
     * @return a string with the contents of the passed file 
7
CodeRank
This code example shows how to use the following methods:close, getEntry, getInputStream
	public static Manifest getManifest(File file) {
		InputStream inputStream = null;
		ZipFile zipFile = null;
 
		try { 
			zipFile = new ZipFile(file);
 
			ZipEntry zipEntry = zipFile.getEntry("META-INF/MANIFEST.MF");
 
			if (zipEntry == null) {
				return null; 
			} 
 
			inputStream = zipFile.getInputStream(zipEntry);
 
			return new Manifest(inputStream);
		} 
		catch (Exception e) {
		} 
		finally { 

7
CodeRank
This code example shows how to use the following methods:close, getEntry
		} 
 
		ZipFile zipFile = null;
 
		try { 
			zipFile = new ZipFile(file);
 
			if (zipFile.getEntry(checkXmlFile) == null) {
				if (_log.isDebugEnabled()) {
					_log.debug(
						file.getPath() + " does not have " + checkXmlFile);
				} 
 
				return false; 
			} 
			else { 
				return true; 
			} 
		} 
		catch (IOException ioe) {

7
CodeRank

Related Java 8 ZipFile Questions & Answers:

See Code Examples for Java 8 ZipFile Methods: