com.appland.appmap.ClassFileExporter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of appmap-agent Show documentation
Show all versions of appmap-agent Show documentation
Inspect and record the execution of Java for use with App Land
The newest version!
package com.appland.appmap;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.DynamicType;
import net.bytebuddy.utility.JavaModule;
public class ClassFileExporter extends AgentBuilder.Listener.Adapter {
private final Path folder;
public ClassFileExporter(Path folder) {
this.folder = folder;
}
@Override
public void onTransformation(TypeDescription typeDescription, ClassLoader classLoader,
JavaModule module, boolean loaded, DynamicType dynamicType) {
try {
Path outputFile = folder.resolve(typeDescription.getName().replace('.', '/') + ".class");
Files.createDirectories(outputFile.getParent());
try (FileOutputStream fos = new FileOutputStream(outputFile.toFile())) {
fos.write(dynamicType.getBytes());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}