private static StringBuilder appendAttributes(StringBuilder manifestEntry, Attributes attributes) { StringBuilder line = new StringBuilder(); if (attributes != null) { for (Map.Entry attr : attributes.entrySet()) { line.append(attr.getKey().toString()).append(": ").append((String) attr.getValue()); appendLine(manifestEntry, line); line.setLength(0); } } return manifestEntry.append("\r\n"); }
private void processMetadataForEntry(final Manifest manifest, final StringBuilder manifestEntries, final StringBuilder sigFileEntries, final String name, final byte[] content) { StringBuilder me = new StringBuilder(); StringBuilder currentLine = new StringBuilder(); // Create digest lines in MANIFEST.MF currentLine.append("Name: ").append(name); appendLine(me, currentLine); currentLine.setLength(0); me.append(digestAlgorithm).append("-Digest: ").append(hash(content)).append("\r\n"); appendAttributes(me, manifest, name); // Create digest lines in ME.SF currentLine.append("Name: ").append(name); appendLine(sigFileEntries, currentLine); currentLine.setLength(0); sigFileEntries.append(digestAlgorithm).append("-Digest: ").append(hash(me.toString())).append("\r\n\r\n"); manifestEntries.append(me); }
/** * Add attributes for the current entry. * * @param manifestEntry - The StringBuilder to which the attributes are to be added. * @param manifest - The Jar Manifest Entry * @param entry - The named entry in the manifest. null means the Main Attribute section. * @return manifestEntry with attributes added. */ private static StringBuilder appendAttributes(StringBuilder manifestEntry, Manifest manifest, String entry) { Attributes attributes = (entry == null) ? manifest.getMainAttributes() : manifest.getAttributes(entry); StringBuilder line = new StringBuilder(); if (attributes != null) { for (Map.Entry attr : attributes.entrySet()) { line.append(attr.getKey().toString()).append(": ").append((String) attr.getValue()); appendLine(manifestEntry, line); line.setLength(0); } } return manifestEntry.append("\r\n"); }
appendLine(me, currentLine); currentLine.setLength(0); me.append(digestAlgorithm).append("-Digest: ").append(hash(jf, je)).append("\r\n"); appendLine(sigFileEntries, currentLine); currentLine.setLength(0); sigFileEntries.append(digestAlgorithm).append("-Digest: ").append(hash(me.toString())).append("\r\n\r\n");