Procyon includes a Java decompiler framework. It's written in Java, and it can be called as a library. There's not much documentation yet, but I am the author, and I can assist you if you run into trouble--just contact me on BitBucket.
A simple example of how to decompile java.lang.String
:
final DecompilerSettings settings = DecompilerSettings.javaDefaults();
try (final FileOutputStream stream = new FileOutputStream("path/to/file");
final OutputStreamWriter writer = new OutputStreamWriter(stream)) {
Decompiler.decompile(
"java.lang.String",
new PlainTextOutput(writer),
settings
);
}
catch (final IOException e) {
// handle error
}
You can also pass a .class
file path to the decompile()
method instead of a class name.
If you're not using Java 7, make sure to flush/close your I/O resources manually, e.g.:
try {
final FileOutputStream stream = new FileOutputStream("path/to/file");
try {
final OutputStreamWriter writer = new OutputStreamWriter(stream);
try {
Decompiler.decompile(
"java.lang.String",
new PlainTextOutput(writer),
DecompilerSettings.javaDefaults()
);
}
finally {
writer.close();
}
}
finally {
stream.close();
}
}
catch (final IOException e) {
// handle error
}