... import org.springframework.boot.loader.jar.JarEntryData; import org.springframework.boot.loader.jar.JarEntryFilter; import org.springframework.boot.loader.jar.JarFile; import org.springframework.boot.loader.tools.JarWriter; import org.springframework.boot.loader.util.AsciiBytes; ... JarWriter writer = new JarWriter(destination); try { JarFile filteredJarFile = sourceJar.getFilteredJarFile(new JarEntryFilter() { @Override public AsciiBytes apply(AsciiBytes name, JarEntryData entryData) { String string = name.toString(); String exp = "^a.*"; if (string.matches(exp)) { string = string.replaceFirst(exp, "replaced"); return new AsciiBytes(string); } return name; } }); writer.writeEntries(filteredJarFile); } finally { try { writer.close(); } catch (Exception ex) { ex.printStackTrace(); } }
private <T extends FileHeader> T getEntry(int hashCode, CharSequence name, char suffix, Class<T> type, boolean cacheEntry, AsciiBytes nameAlias) { int index = getFirstIndex(hashCode); while (index >= 0 && index < this.size && this.hashCodes[index] == hashCode) { T entry = getEntry(index, type, cacheEntry, nameAlias); if (entry.hasName((nameAlias != null) ? nameAlias.toString() : name, suffix)) { return entry; } index++; } return null; }
private StringSequence decode(StringSequence source) { if (source.isEmpty() || (source.indexOf('%') < 0)) { return source; } ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length()); write(source.toString(), bos); // AsciiBytes is what is used to store the JarEntries so make it symmetric return new StringSequence(AsciiBytes.toString(bos.toByteArray())); }
JarEntry(JarFile jarFile, CentralDirectoryFileHeader header, AsciiBytes nameAlias) { super((nameAlias != null) ? nameAlias.toString() : header.getName().toString()); this.name = (nameAlias != null) ? nameAlias : header.getName(); this.jarFile = jarFile; this.localHeaderOffset = header.getLocalHeaderOffset(); setCompressedSize(header.getCompressedSize()); setMethod(header.getMethod()); setCrc(header.getCrc()); setComment(header.getComment().toString()); setSize(header.getSize()); setTime(header.getTime()); setExtra(header.getExtra()); }