long size = location != null ? location.getUncompressedSize() : 0;
System.out.printf("reading: module: %s, path: %s, size: %d%n",
moduleName, className, size); if (moduleName.contains("NOSUCH") || className.contains("NOSUCH")) { Assert.assertTrue(location == null, "location found for non-existing module: "
+ moduleName
+ ", or class: " + className); return; // no more to test for non-existing class
} else { Assert.assertTrue(location != null, "location not found: " + className); Assert.assertTrue(size > 0, "size of should be > 0: " + className);
}
// positive: read whole class
ByteBuffer buffer = reader.getResourceBuffer(location); Assert.assertTrue(buffer != null, "bytes read not equal bytes requested");
if (className.endsWith(".class")) { int m = buffer.getInt(); Assert.assertEquals(m, classMagic, "Classfile has bad magic number");
}
int next = 0;
String m = null;
String p = null;
String b = null;
String e = null; if (path.startsWith("/")) {
next = path.indexOf('/', 1);
m = path.substring(1, next);
next = next + 1;
} int lastSlash = path.lastIndexOf('/'); if (lastSlash > next) { // has a parent
p = path.substring(next, lastSlash);
next = lastSlash + 1;
} int period = path.indexOf('.', next); if (period > next) {
b = path.substring(next, period);
e = path.substring(period + 1);
} else {
b = path.substring(next);
} Assert.assertNotNull(m, "module must be non-empty"); Assert.assertNotNull(b, "base name must be non-empty");
}
// Read all the names from the native JIMAGE API
String[] nativeNames = JIMAGE_Names(); //writeNames("/tmp/native-names.txt", nativeNames); // debug
int modCount = 0; int pkgCount = 0; int otherCount = 0; for (String n : nativeNames) { if (n.startsWith("/modules/")) {
modCount++;
} elseif (n.startsWith("/packages/")) {
pkgCount++;
} else {
otherCount++;
}
}
System.out.printf("native name count: %d, modCount: %d, pkgCount: %d, otherCount: %d%n",
names.length, modCount, pkgCount, otherCount);
// Sort and merge the two arrays. Every name should appear exactly twice.
Arrays.sort(names);
Arrays.sort(nativeNames);
String[] combined = Arrays.copyOf(names, nativeNames.length + names.length);
System.arraycopy(nativeNames,0, combined, names.length, nativeNames.length);
Arrays.sort(combined); int missing = 0; for (int i = 0; i < combined.length; i++) {
String s = combined[i]; if (isMetaName(s)) { // Ignore /modules and /packages in BasicImageReader names continue;
}
if (i < combined.length - 1 && s.equals(combined[i + 1])) {
i++; // string appears in both java and native continue;
}
missing++; int ndx = Arrays.binarySearch(names, s);
String which = (ndx >= 0) ? "java BasicImageReader" : "native JIMAGE_Resources";
System.out.printf("Missing Resource: %s found only via %s%n", s, which);
} Assert.assertEquals(missing, 0, "Resources missing");
// Write an array of names to a file for debugging staticvoid writeNames(String fname, String[] names) throws IOException { try (FileWriter wr = new FileWriter(new File(fname))) { for (String s : names) {
wr.write(s);
wr.write("\n");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.