publicvoid run() throws Exception { // create a simple test class which we can put into // a test zip file and know that it will be used by // javap.
File classDir = new File("classes");
classDir.mkdir();
void test(File classDir, String className, boolean useJavaUtilZip) throws Exception { // javac should really not be using system properties like this // -- it should really be using (hidden) options -- but until then // take care to leave system properties as we find them, so as not // to adversely affect other tests that might follow.
String prev = System.getProperty("useJavaUtilZip");
setProperty("useJavaUtilZip", (useJavaUtilZip ? "true" : null)); try {
File zipFile = zip(classDir, new File(classDir + ".zip"));
javap("-classpath", zipFile.getPath(), className);
if (!zipFile.delete()) thrownew Exception("failed to delete " + zipFile);
} finally {
setProperty("useJavaUtilZip", prev);
}
}
File writeTestFile(String name) throws IOException {
File f = new File(name + ".java");
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(f)));
out.println("class " + name + " { }");
out.close(); return f;
}
void compileTestFile(File classDir, File file) { int rc = com.sun.tools.javac.Main.compile( new String[] { "-d", classDir.getPath(), file.getPath() }); if (rc != 0) thrownew Error("compilation failed. rc=" + rc);
}
File zip(File dir, File zipFile) throws IOException {
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile)); for (File file: dir.listFiles()) { if (file.isFile()) { byte[] data = newbyte[(int) file.length()];
DataInputStream in = new DataInputStream(new FileInputStream(file));
in.readFully(data);
in.close();
zipOut.putNextEntry(new ZipEntry(file.getName()));
zipOut.write(data, 0, data.length);
zipOut.closeEntry();
}
}
zipOut.close(); return zipFile;
}
String javap(String... args) {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw); int rc = com.sun.tools.javap.Main.run(args, out); if (rc != 0) thrownew Error("javap failed. rc=" + rc);
out.close(); return sw.toString();
}
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.