下面列出了java.util.jar.Attributes#isEmpty ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void writeIndividualSection(OutputStream out, String name, Attributes attributes)
throws IOException {
writeAttribute(out, "Name", name);
if (!attributes.isEmpty()) {
writeAttributes(out, getAttributesSortedByName(attributes));
}
writeSectionDelimiter(out);
}
/**
* Compares two manifest files. First check is for number of attributes,
* next one is comparing name-value pairs.
*
*@param mf1, mf2 manifests to compare
*@param ignoredEntries array of manifest entries to ignore
*@return true if files contains the same entries/values in manifest
*/
public static boolean equalsManifest(File mf1, File mf2, String[] ignoredEntries) {
if (ignoredEntries == null) {
ignoredEntries = new String[] {};
}
try {
Manifest m1 = new Manifest(new FileInputStream(mf1));
Manifest m2 = new Manifest(new FileInputStream(mf2));
Attributes a1 = m1.getMainAttributes();
Attributes a2 = m2.getMainAttributes();
if (a1.size() != a2.size()) {
return false;
}
for (Iterator<Object> i = a1.keySet().iterator(); i.hasNext();) {
Attributes.Name a = (Attributes.Name) i.next();
boolean b = true;
for (int j = 0; j < ignoredEntries.length; j++) {
if (a.toString().equals(ignoredEntries[j])) {
a2.remove(a);
b = false;
break;
}
}
if (b && (a1.get(a).equals(a2.get(a)))) {
a2.remove(a);
}
}
return a2.isEmpty();
} catch (FileNotFoundException fnfe) {
LOGGER.log(Level.WARNING, "Exception from test - comparing manifests", fnfe); //NOI18N
} catch (IOException ioe) {
LOGGER.log(Level.WARNING, "Exception from test - comparing manifests", ioe); //NOI18N
}
return false;
}
/**
* Compares two manifest files. First check is for number of attributes,
* next one is comparing name-value pairs.
*
*@param mf1, mf2 manifests to compare
*@param ignoredEntries array of manifest entries to ignore
*@return true if files contains the same entries/values in manifest
*/
public static boolean equalsManifest(File mf1, File mf2, String[] ignoredEntries) {
if (ignoredEntries == null) {
ignoredEntries = new String[]{};
}
try {
Manifest m1 = new Manifest(new FileInputStream(mf1));
Manifest m2 = new Manifest(new FileInputStream(mf2));
Attributes a1 = m1.getMainAttributes();
Attributes a2 = m2.getMainAttributes();
if (a1.size() != a2.size()) {
return false;
}
for (Iterator<Object> i = a1.keySet().iterator(); i.hasNext();) {
Attributes.Name a = (Attributes.Name) i.next();
boolean b = true;
for (int j = 0; j < ignoredEntries.length; j++) {
if (a.toString().equals(ignoredEntries[j])) {
a2.remove(a);
b = false;
break;
}
}
if (b && (a1.get(a).equals(a2.get(a)))) {
a2.remove(a);
}
}
return a2.isEmpty();
} catch (FileNotFoundException fnfe) {
System.err.println("Exception from test - comparing manifests");
fnfe.printStackTrace(System.err);
} catch (IOException ioe) {
System.err.println("Exception from test - comparing manifests");
ioe.printStackTrace(System.err);
}
return false;
}
public static void writeIndividualSection(OutputStream out, String name, Attributes attributes)
throws IOException {
writeAttribute(out, "Name", name);
if (!attributes.isEmpty()) {
writeAttributes(out, getAttributesSortedByName(attributes));
}
writeSectionDelimiter(out);
}
private static void fixManifest(Manifest manifest, TinyRemapper remapper) {
Attributes mainAttrs = manifest.getMainAttributes();
if (remapper != null) {
String val = mainAttrs.getValue(Attributes.Name.MAIN_CLASS);
if (val != null) mainAttrs.put(Attributes.Name.MAIN_CLASS, mapFullyQualifiedClassName(val, remapper));
val = mainAttrs.getValue("Launcher-Agent-Class");
if (val != null) mainAttrs.put("Launcher-Agent-Class", mapFullyQualifiedClassName(val, remapper));
}
mainAttrs.remove(Attributes.Name.SIGNATURE_VERSION);
for (Iterator<Attributes> it = manifest.getEntries().values().iterator(); it.hasNext(); ) {
Attributes attrs = it.next();
for (Iterator<Object> it2 = attrs.keySet().iterator(); it2.hasNext(); ) {
Attributes.Name attrName = (Attributes.Name) it2.next();
String name = attrName.toString();
if (name.endsWith("-Digest") || name.contains("-Digest-") || name.equals("Magic")) {
it2.remove();
}
}
if (attrs.isEmpty()) it.remove();
}
}
private void updateManifest(int manifestIndex, String inName, String outName, MessageDigest[] digests)
{
// Create fresh section for entry, and enter "Name" header
Manifest nm = newManifest[manifestIndex];
Manifest om = oldManifest[manifestIndex];
Attributes oldAtts = om.getAttributes(inName);
Attributes newAtts = new Attributes();
//newAtts.putValue(MANIFEST_NAME_TAG, outName);
// copy over non-name and none digest entries
if (oldAtts != null){
for(Iterator it = oldAtts.entrySet().iterator(); it.hasNext();){
Map.Entry entry = (Map.Entry) it.next();
Object key = entry.getKey();
String name = key.toString();
if (!name.equalsIgnoreCase(MANIFEST_NAME_TAG) &&
name.indexOf("Digest") == -1){
newAtts.remove(name);
newAtts.putValue(name, (String)entry.getValue());
}
}
}
// Create fresh digest entries in the new section
if (digests != null && digests.length > 0)
{
// Digest-Algorithms header
StringBuffer sb = new StringBuffer();
for (int i = 0; i < digests.length; i++)
{
sb.append(digests[i].getAlgorithm());
if (i < digests.length -1){
sb.append(", ");
}
}
newAtts.remove(MANIFEST_DIGESTALG_TAG);
newAtts.putValue(MANIFEST_DIGESTALG_TAG, sb.toString());
// *-Digest headers
for (int i = 0; i < digests.length; i++)
{
newAtts.remove(digests[i].getAlgorithm() + "-Digest");
newAtts.putValue(digests[i].getAlgorithm() + "-Digest", Tools.toBase64(digests[i].digest()));
}
}
if (!newAtts.isEmpty()) {
// Append the new section to the new manifest
nm.getEntries().put(outName, newAtts);
}
}