public JarFileArchive(File file, URL url) throws IOException { this(new JarFile(file)); this.url = url; }
public BootApplicationConfigurationMetadataResolver(ClassLoader parent) { this.parent = parent; JarFile.registerUrlProtocolHandler(); try { Resource[] globalResources = new PathMatchingResourcePatternResolver( ApplicationConfigurationMetadataResolver.class.getClassLoader()).getResources(WHITELIST_PROPERTIES); loadWhiteLists(globalResources, globalWhiteListedClasses, globalWhiteListedProperties); } catch (IOException e) { throw new RuntimeException("Error reading global white list of configuration properties", e); } }
@Override public Iterator<Entry> iterator() { return new EntryIterator(this.jarFile.entries()); }
private JarFile getNestedJarFile(JarFile jarFile, String name) throws IOException { JarEntry jarEntry = jarFile.getJarEntry(name); return jarFile.getNestedJarFile(jarEntry); }
static JarURLConnection get(URL url, JarFile jarFile) throws IOException { StringSequence spec = new StringSequence(url.getFile()); int index = indexOfRootSpec(spec, jarFile.getPathFromRoot()); if (index == -1) { return (Boolean.TRUE.equals(useFastExceptions.get()) ? NOT_FOUND_CONNECTION : new JarURLConnection(url, null, EMPTY_JAR_ENTRY_NAME)); } int separator; while ((separator = spec.indexOf(SEPARATOR, index)) > 0) { JarEntryName entryName = JarEntryName.get(spec.subSequence(index, separator)); JarEntry jarEntry = jarFile.getJarEntry(entryName.toCharSequence()); if (jarEntry == null) { return JarURLConnection.notFound(jarFile, entryName); } jarFile = jarFile.getNestedJarFile(jarEntry); index = separator + SEPARATOR.length(); } JarEntryName jarEntryName = JarEntryName.get(spec, index); if (Boolean.TRUE.equals(useFastExceptions.get()) && !jarEntryName.isEmpty() && !jarFile.containsEntry(jarEntryName.toString())) { return NOT_FOUND_CONNECTION; } return new JarURLConnection(url, jarFile, jarEntryName); }
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); } }
@Override public InputStream getInputStream() throws IOException { if (this.jarFile == null) { throw FILE_NOT_FOUND_EXCEPTION; } if (this.jarEntryName.isEmpty() && this.jarFile.getType() == JarFile.JarFileType.DIRECT) { throw new IOException("no entry name specified"); } connect(); InputStream inputStream = (this.jarEntryName.isEmpty() ? this.jarFile.getData().getInputStream() : this.jarFile.getInputStream(this.jarEntry)); if (inputStream == null) { throwFileNotFound(this.jarEntryName, this.jarFile); } return inputStream; }
private void unpack(JarEntry entry, File file) throws IOException { try (InputStream inputStream = this.jarFile.getInputStream(entry); OutputStream outputStream = new FileOutputStream(file)) { byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.flush(); } }
private JarFile(RandomAccessDataFile rootFile, String pathFromRoot, RandomAccessData data, JarEntryFilter filter, JarFileType type, Supplier<Manifest> manifestSupplier) throws IOException { super(rootFile.getFile()); this.rootFile = rootFile; this.pathFromRoot = pathFromRoot; CentralDirectoryParser parser = new CentralDirectoryParser(); this.entries = parser.addVisitor(new JarFileEntries(this, filter)); parser.addVisitor(centralDirectoryVisitor()); this.data = parser.parse(data, filter == null); this.type = type; this.manifestSupplier = (manifestSupplier != null) ? manifestSupplier : () -> { try (InputStream inputStream = getInputStream(MANIFEST_NAME)) { if (inputStream == null) { return null; } return new Manifest(inputStream); } catch (IOException ex) { throw new RuntimeException(ex); } }; }
/** * 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(ZipEntry entry) throws IOException { return getNestedJarFile((JarEntry) entry); }
@Override public void connect() throws IOException { if (this.jarFile == null) { throw FILE_NOT_FOUND_EXCEPTION; } if (!this.jarEntryName.isEmpty() && this.jarEntry == null) { this.jarEntry = this.jarFile.getJarEntry(getEntryName()); if (this.jarEntry == null) { throwFileNotFound(this.jarEntryName, this.jarFile); } } this.connected = true; }
@Override public synchronized InputStream getInputStream(ZipEntry entry) throws IOException { if (entry instanceof JarEntry) { return this.entries.getInputStream((JarEntry) entry); } return getInputStream((entry != null) ? entry.getName() : null); }
protected Archive getNestedArchive(Entry entry) throws IOException { JarEntry jarEntry = ((JarFileEntry) entry).getJarEntry(); if (jarEntry.getComment().startsWith(UNPACK_MARKER)) { return getUnpackedNestedArchive(jarEntry); } try { JarFile jarFile = this.jarFile.getNestedJarFile(jarEntry); return new JarFileArchive(jarFile); } catch (Exception ex) { throw new IllegalStateException( "Failed to get nested archive for entry " + entry.getName(), ex); } }
private JarFile getRootJarFile(String name) throws IOException { try { if (!name.startsWith(FILE_PROTOCOL)) { throw new IllegalStateException("Not a file URL"); } String path = name.substring(FILE_PROTOCOL.length()); File file = new File(URLDecoder.decode(path, "UTF-8")); Map<File, JarFile> cache = rootFileCache.get(); JarFile result = (cache != null) ? cache.get(file) : null; if (result == null) { result = new JarFile(file); addToRootFileCache(file, result); } return result; } catch (Exception ex) { throw new IOException("Unable to open root Jar file '" + name + "'", ex); } }
public BootApplicationConfigurationMetadataResolver(ClassLoader parent) { this.parent = parent; JarFile.registerUrlProtocolHandler(); try { Resource[] globalResources = new PathMatchingResourcePatternResolver(ApplicationConfigurationMetadataResolver.class.getClassLoader()).getResources(WHITELIST_PROPERTIES); loadWhiteLists(globalResources, globalWhiteListedClasses, globalWhiteListedProperties); } catch (IOException e) { throw new RuntimeException("Error reading global white list of configuration properties", e); } }
/** * * unpack jar to temp folder * @param jarFile * @return */ public static Integer unpackBootLibs(JarFile jarFile) throws IOException { Enumeration<JarEntry> entries = jarFile.entries(); int count = 0; while (entries.hasMoreElements()) { JarEntry jarEntry = entries.nextElement(); if (jarEntry.getName().startsWith(BOOT_INF_LIB) && jarEntry.getName().endsWith(".jar")) { getUnpackedNestedArchive(jarFile, jarEntry); count++; } } return count; }
/** * * @param jarFile * @param entry * @param file * @throws IOException */ private static void unpack(JarFile jarFile, JarEntry entry, File file) throws IOException { InputStream inputStream = jarFile.getInputStream(entry, RandomAccessData.ResourceAccess.ONCE); try { OutputStream outputStream = new FileOutputStream(file); try { byte[] buffer = new byte[BUFFER_SIZE]; int bytesRead = -1; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } outputStream.flush(); } finally { outputStream.close(); } } finally { inputStream.close(); } }
"Unable to determine code source archive from " + root); return new JarFile(root);
public BootApplicationConfigurationMetadataResolver(ClassLoader parent) { this.parent = parent; JarFile.registerUrlProtocolHandler(); try { // read both formats and concat Resource[] globalLegacyResources = new PathMatchingResourcePatternResolver( ApplicationConfigurationMetadataResolver.class.getClassLoader()) .getResources(WHITELIST_LEGACY_PROPERTIES); Resource[] globalResources = new PathMatchingResourcePatternResolver( ApplicationConfigurationMetadataResolver.class.getClassLoader()) .getResources(WHITELIST_PROPERTIES); loadWhiteLists(concatArrays(globalLegacyResources, globalResources), globalWhiteListedClasses, globalWhiteListedProperties); } catch (IOException e) { throw new RuntimeException("Error reading global white list of configuration properties", e); } }