use of aQute.libg.classdump.ClassDumper in project bnd by bndtools.
the class bnd method _view.
/**
* View files from JARs We parse the commandline and print each file on it.
*
* @throws Exception
*/
@Description("View a resource from a JAR file.")
public void _view(viewOptions options) throws Exception {
Charset charset = UTF_8;
if (options.charset() != null)
charset = Charset.forName(options.charset());
if (options._arguments().isEmpty()) {
error("Need a jarfile as source");
return;
}
List<String> args = options._arguments();
File file = getFile(args.remove(0));
if (!file.isFile()) {
error("File does not exist %s", file);
return;
}
try (Jar jar = new Jar(file)) {
if (args.isEmpty())
args.add("*");
Instructions instructions = new Instructions(args);
Collection<String> selected = instructions.select(jar.getResources().keySet(), true);
for (String selection : selected) {
Resource r = jar.getResource(selection);
if (selection.endsWith(".MF")) {
Manifest m = new Manifest(r.openInputStream());
printManifest(m);
} else if (selection.endsWith(".class")) {
ClassDumper clsd = new ClassDumper(selection, r.openInputStream());
clsd.dump(out);
} else {
InputStreamReader isr = new InputStreamReader(r.openInputStream(), charset);
IO.copy(isr, out);
}
}
}
}
Aggregations