private JarFile createJarFileFromFileEntry(JarEntryData sourceEntry) throws IOException { if (sourceEntry.getMethod() != ZipEntry.STORED) { throw new IllegalStateException( "Unable to open nested compressed entry " + sourceEntry.getName()); } return new JarFile( this.rootFile, this.pathFromRoot + "!/" + sourceEntry.getName(), sourceEntry.getData()); }
/** * Return a nested {@link JarFile} loaded from the specified entry. * * @param sourceEntry the zip entry * @return a {@link JarFile} for the entry * @throws IOException */ public synchronized JarFile getNestedJarFile(JarEntryData sourceEntry) throws IOException { try { if (sourceEntry.nestedJar == null) { sourceEntry.nestedJar = createJarFileFromEntry(sourceEntry); } return sourceEntry.nestedJar; } catch (IOException ex) { throw new IOException("Unable to open nested jar file '" + sourceEntry.getName() + "'", ex); } }
private List<JarEntryData> filterEntries(List<JarEntryData> entries, JarEntryFilter[] filters) { List<JarEntryData> filteredEntries = new ArrayList<JarEntryData>(entries.size()); for (JarEntryData entry : entries) { AsciiBytes name = entry.getName(); for (JarEntryFilter filter : filters) { name = (filter == null || name == null ? name : filter.apply(name, entry)); } if (name != null) { JarEntryData filteredCopy = entry.createFilteredCopy(this, name); filteredEntries.add(filteredCopy); processEntry(filteredCopy); } } return filteredEntries; }
private List<JarEntryData> loadJarEntries(CentralDirectoryEndRecord endRecord) throws IOException { RandomAccessData centralDirectory = endRecord.getCentralDirectory(this.data); int numberOfRecords = endRecord.getNumberOfRecords(); List<JarEntryData> entries = new ArrayList<JarEntryData>(numberOfRecords); InputStream inputStream = centralDirectory.getInputStream(ResourceAccess.ONCE); try { JarEntryData entry = JarEntryData.fromInputStream(this, inputStream); while (entry != null) { entries.add(entry); processEntry(entry); entry = JarEntryData.fromInputStream(this, inputStream); } } finally { inputStream.close(); } return entries; }
private JarFile createJarFileFromDirectoryEntry(JarEntryData sourceEntry) throws IOException { final AsciiBytes sourceName = sourceEntry.getName(); JarEntryFilter filter = new JarEntryFilter() { @Override public AsciiBytes apply(AsciiBytes name, JarEntryData entryData) { if (name.startsWith(sourceName) && !name.equals(sourceName)) { return name.substring(sourceName.length()); } return null; } }; return new JarFile( this.rootFile, this.pathFromRoot + "!/" + sourceEntry.getName().substring(0, sourceName.length() - 1), this.data, this.entries, filter); }
public JarEntryData getJarEntryData(AsciiBytes name) { if (name == null) { return null; } Map<AsciiBytes, JarEntryData> entriesByName = (this.entriesByName == null ? null : this.entriesByName.get()); if (entriesByName == null) { entriesByName = new HashMap<AsciiBytes, JarEntryData>(); for (JarEntryData entry : this.entries) { entriesByName.put(entry.getName(), entry); } this.entriesByName = new SoftReference<Map<AsciiBytes, JarEntryData>>(entriesByName); } JarEntryData entryData = entriesByName.get(name); if (entryData == null && !name.endsWith(SLASH)) { entryData = entriesByName.get(name.append(SLASH)); } return entryData; }
private JarFile createJarFileFromEntry(JarEntryData sourceEntry) throws IOException { if (sourceEntry.isDirectory()) { return createJarFileFromDirectoryEntry(sourceEntry); } return createJarFileFromFileEntry(sourceEntry); }
@Override public ZipEntry getEntry(String name) { JarEntryData jarEntryData = getJarEntryData(name); return (jarEntryData == null ? null : jarEntryData.asJarEntry()); }
private void processEntry(JarEntryData entry) { AsciiBytes name = entry.getName(); if (name.startsWith(META_INF)) { processMetaInfEntry(name, entry); } }