ProgramResourceLocator[] members = resourceRepository.getMembers(moduleFolder);
for (int fileN = 0, nFiles = members.length; fileN < nFiles; ++fileN) {
ProgramResourceLocator member = members[fileN];
String name = member.getName();
// Skip anything which isn't a class file.
if (!(member instanceof ProgramResourceLocator.File) || !name.toLowerCase().endsWith(".class")) {
continue;
}
ProgramResourceLocator.File classFileLocator = (ProgramResourceLocator.File)member;
byte[] bytecode;
InputStream classFileContents = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
classFileContents = resourceRepository.getContents(classFileLocator);
byte[] buf = new byte[4096];
while (true) {
int bytesRead = classFileContents.read(buf);
if (bytesRead < 0) {
break;
}
baos.write(buf, 0, bytesRead);
}
bytecode = baos.toByteArray();
} catch (IOException ioe) {
throw new RuntimeException("Could not read the class file " + member.getName() + ".");
} finally {
if (classFileContents != null) {
try {
classFileContents.close();
} catch (IOException e) {
}
}
}
final boolean dumpAsmifiedText = true;
final boolean dumpDisassembledText = true;
final boolean verifyClassFileFormat = true;
//javac generates many debug op codes, such as line number annotations. For comparison with the asm
//generated byte codes we can skip these.
final boolean skipDebugOpCodes = true;
final boolean skipInnerClassAttributes = false;
String classFileName = member.getName();
String className = classFileName.substring(0, classFileName.length() - ".class".length());
String moduleName = moduleFolder.getModuleName().toString().replaceAll("_", "__").replace('.', '_');
if (dumpAsmifiedText) {
String asmifierDumpPath = "d:\\dev\\asmifierOutput\\javaSource\\" + moduleName + "\\" + className + ".txt";