private JarFile createJarFileFromFileEntry(JarEntry entry) throws IOException { if (entry.getMethod() != ZipEntry.STORED) { throw new IllegalStateException("Unable to open nested entry '" + entry.getName() + "'. It has been compressed and nested " + "jar files must be stored without compression. Please check the " + "mechanism used to create your executable jar file"); } RandomAccessData entryData = this.entries.getEntryData(entry.getName()); return new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName(), entryData, JarFileType.NESTED_JAR); }
/** * Return a {@link URL} for this {@link JarEntry}. * @return the URL for the entry * @throws MalformedURLException if the URL is not valid */ URL getUrl() throws MalformedURLException { return new URL(this.jarFile.getUrl(), getName()); }
/** * Return a nested {@link JarFile} loaded from the specified entry. * @param entry the zip entry * @return a {@link JarFile} for the entry * @throws IOException if the nested jar file cannot be read */ public synchronized JarFile getNestedJarFile(JarEntry entry) throws IOException { try { return createJarFileFromEntry(entry); } catch (Exception ex) { throw new IOException( "Unable to open nested jar file '" + entry.getName() + "'", ex); } }
@Override public Attributes getAttributes() throws IOException { Manifest manifest = this.jarFile.getManifest(); return (manifest != null) ? manifest.getAttributes(getName()) : null; }
void setupEntryCertificates(JarEntry entry) { // Fallback to JarInputStream to obtain certificates, not fast but hopefully not // happening that often. try { try (JarInputStream inputStream = new JarInputStream( getData().getInputStream())) { java.util.jar.JarEntry certEntry = inputStream.getNextJarEntry(); while (certEntry != null) { inputStream.closeEntry(); if (entry.getName().equals(certEntry.getName())) { setCertificates(entry, certEntry); } setCertificates(getJarEntry(certEntry.getName()), certEntry); certEntry = inputStream.getNextJarEntry(); } } } catch (IOException ex) { throw new IllegalStateException(ex); } }
private JarFile createJarFileFromDirectoryEntry(JarEntry entry) throws IOException { AsciiBytes name = entry.getAsciiBytesName(); JarEntryFilter filter = (candidate) -> { if (candidate.startsWith(name) && !candidate.equals(name)) { return candidate.substring(name.length()); } return null; }; return new JarFile(this.rootFile, this.pathFromRoot + "!/" + entry.getName().substring(0, name.length() - 1), this.data, filter, JarFileType.NESTED_DIRECTORY, this.manifestSupplier); }