File writeTestFile() throws IOException {
File f = new File("Test.java");
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
out.println("@Deprecated class Test { int f; void m() { } }");
out.close(); return f;
}
// copy class attributes, adding in new attribute
out.writeShort(attributes_count + 1);
out.write(data, classAttributesPos + 2, data.length - classAttributesPos - 2);
out.writeShort(constant_pool_count); // index of new attribute name
out.writeInt(newAttributeData.length);
out.write(newAttributeData);
out.close();
}
int skipConstantPool(DataInputStream in) throws IOException { int constant_pool_count = in.readUnsignedShort(); for (int i = 1; i < constant_pool_count; i++) { int tag = in.readUnsignedByte(); switch (tag) { case1: // CONSTANT_Utf8 int length = in.readUnsignedShort();
in.skipBytes(length); // bytes break;
int skipAttributes(DataInputStream in) throws IOException { int attributes_count = in.readUnsignedShort(); for (int i = 0; i < attributes_count; i++) {
in.skipBytes(2); // attribute_name_index; int length = in.readInt();
in.skipBytes(length); // info
} return attributes_count;
}
String javap(File f) {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw); int rc = com.sun.tools.javap.Main.run(new String[] { "-v", f.getPath() }, out); if (rc != 0) thrownew Error("javap failed. rc=" + rc);
out.close(); return sw.toString();
}
void verify(String output) {
System.out.println(output);
output = output.substring(output.indexOf("Test.java")); if (output.indexOf("-") >= 0) thrownew Error("- found in output"); if (output.indexOf("FFFFFF") >= 0) thrownew Error("FFFFFF found in output");
}
}
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.