Java 8 JarEntry - 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 JarEntry class.

This code example shows how to use the following methods:setCrc, setMethod, setSize, setTime
 
	public void addZipEntry(ZipEntry zipEntry, ZipFile zipFile, String path) throws IOException {
		if (fJarPackage.areDirectoryEntriesIncluded())
			addDirectories(path);
 
		JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/'));
 
		if (fJarPackage.isCompressed())
			newEntry.setMethod(ZipEntry.DEFLATED);
			// Entry is filled automatically. 
		else { 
			newEntry.setMethod(ZipEntry.STORED);
			newEntry.setSize(zipEntry.getSize());
			newEntry.setCrc(zipEntry.getCrc());
		} 
 
		long lastModified= System.currentTimeMillis();
 
		// Set modification time 
		newEntry.setTime(lastModified);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setCrc, setMethod, setSize, setTime
 
	public void addZipEntry(ZipEntry zipEntry, ZipFile zipFile, String path) throws IOException {
		if (fJarPackage.areDirectoryEntriesIncluded())
			addDirectories(path);
 
		JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/'));
 
		if (fJarPackage.isCompressed())
			newEntry.setMethod(ZipEntry.DEFLATED);
			// Entry is filled automatically. 
		else { 
			newEntry.setMethod(ZipEntry.STORED);
			newEntry.setSize(zipEntry.getSize());
			newEntry.setCrc(zipEntry.getCrc());
		} 
 
		long lastModified= System.currentTimeMillis();
 
		// Set modification time 
		newEntry.setTime(lastModified);

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isDirectory
        switch (protocol) {
            case "jar": 
                try { 
                    final JarURLConnection jarConnection = (JarURLConnection) resourceURL.openConnection();
                    final JarEntry entry = jarConnection.getJarEntry();
                    if (entry.isDirectory()) {
                        return true; 
                    } 
 
                    // WARNING! Heuristics ahead. 
                    // It turns out that JarEntry#isDirectory() really just tests whether the filename ends in a '/'. If you try 
                    // to open the same URL without a trailing '/', it'll succeed — but the result won't be what you want. 
                    // We try to get around this by calling getInputStream() on the file inside the jar. This seems to return null 
                    // for directories (though that behavior is undocumented as far as I can tell). If you have a better idea, 
                    // please improve this. 
 
                    String filename = resourceURL.getFile();
                    filename = filename.substring(filename.indexOf('!') + 2); // leaves just the relative file path inside the jar
                    final JarFile jarFile = jarConnection.getJarFile();
                    final ZipEntry zipEntry = jarFile.getEntry(filename);
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setMethod, setTime
 
	private void addFile(File file, IPath path) throws IOException {
		if (fJarPackage.areDirectoryEntriesIncluded())
			addDirectories(path);
 
		JarEntry newEntry= new JarEntry(path.toString().replace(File.separatorChar, '/'));
 
		if (fJarPackage.isCompressed())
			newEntry.setMethod(ZipEntry.DEFLATED);
			// Entry is filled automatically. 
		else { 
			newEntry.setMethod(ZipEntry.STORED);
			JarPackagerUtil.calculateCrcAndSize(newEntry, new FileInputStream(file), new byte[4096]);
		} 
 
		newEntry.setTime(file.lastModified());
		addEntry(newEntry, new FileInputStream(file));
	} 
} 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getName, isDirectory
		return classes;
	} 
 
	private void addClassFromJar(JarEntry jarEntry, List<Class<?>> classes) {
		if (isMatchingClass(jarEntry)) {
			String fileName = jarEntry.getName();
			if (isValidClassName(fileName)) {
				Class<?> clazz = createClass(fileName);
				if (isNotNull(clazz)) {
					classes.add(clazz);
				} 
			} 
		} 
	} 
 
	private boolean isMatchingClass(JarEntry jarEntry) {
 
		boolean retVal = false;
		if (!jarEntry.isDirectory()) {
			String name = jarEntry.getName();

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setSize, setTime
        final byte[] embeddedJar = buildEmbeddedJar();
 
        final File ear = new File(TMP_DIR, getEarName());
 
        final JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(ear));
        packageResource(embeddedJar, jarOutputStream, new JarEntry("lib/embedded.jar"));
 
        final byte[] testXml = getResource("/ear-contents/test.xml"),
                testTxt = getResource("/ear-contents/test.txt"),
                manifest = getResource("/ear-contents/MANIFEST.MF"),
                testProperties = getResource("/ear-contents/test.properties");
 
        packageResource(testXml, "/META-INF/test.xml", jarOutputStream);
        packageResource(testTxt, "META-INF/test.txt", jarOutputStream);
        packageResource(manifest, "META-INF/MANIFEST.MF", jarOutputStream);
        packageResource(testProperties, "META-INF/config/test.properties", jarOutputStream);
 
        jarOutputStream.close();
 
        onSetup(); 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getName, isDirectory
        return rscs;
    } 
 
    private void visit(List<JarEntry> classFiles, JarEntry entry) {
        // String name = entry.getName(); 
        if (!entry.isDirectory() && entry.getName().endsWith(SUFFIX)) {
            classFiles.add(entry);
        } 
    } 
 
    @Override 
    public String getContextName() {
        return m_file.getAbsolutePath();
    } 
 
    @Override 
    public String getContextDescription() {
        return DESCRIPTION;
    } 
 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getSize
    { 
        if (isDirectory()) 
            return -1; 
 
        if (_entry!=null)
            return _entry.getSize();
         
        return -1; 
    } 
     
    /* ------------------------------------------------------------ */ 
    /** Encode according to this resource type. 
     * File URIs are not encoded. 
     * @param uri URI to encode. 
     * @return The uri unchanged. 
     */ 
    public String encode(String uri)
    { 
        return uri;
    } 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getTime
        final JarEntry entry = jarConnection.getJarEntry();
 
        assertThat(lastModified)
                .isGreaterThan(0); 
        assertThat(lastModified)
                .isEqualTo(entry.getTime());
    } 
 
    @Test
    public void getLastModifiedReturnsZeroIfAnErrorOccurs() throws Exception {
        final URL url = new URL("file:/some/path/that/doesnt/exist");
        final long lastModified = ResourceURL.getLastModified(url);
 
        assertThat(lastModified)
                .isZero(); 
    } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getName
        return createURL(jarFile, jarEntry, new File(jarFile.getName()).toURI().toURL());
    } 
 
    public static URL createURL(JarFile jarFile, JarEntry jarEntry, URL codeSource) throws MalformedURLException {
        JarFileUrlStreamHandler handler = new JarFileUrlStreamHandler(jarFile, jarEntry);
        URL url = new URL("jar", "", -1, codeSource + "!/" + jarEntry.getName(), handler);
        handler.setExpectedUrl(url);
        return url;
    } 
 
    public JarFileUrlStreamHandler(JarFile jarFile, JarEntry jarEntry) {
        if (jarFile == null) {
            throw new NullPointerException("jarFile is null");
        } 
        if (jarEntry == null) {
            throw new NullPointerException("jarEntry is null");
        } 
 
        this.jarFile = jarFile;
        this.jarEntry = jarEntry;
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Java 8 JarEntry Questions & Answers:

See Code Examples for Java 8 JarEntry Methods: