feat: support bytecode shrink

1. remove source file symbol (#46)
2. remove debug info when enable shrink (#29)
This commit is contained in:
ReaJason
2025-02-26 20:19:30 +08:00
parent 7927611c92
commit cf2b2af67e
16 changed files with 94 additions and 27 deletions
@@ -0,0 +1,26 @@
package com.reajason.javaweb;
import net.bytebuddy.jar.asm.ClassReader;
import net.bytebuddy.jar.asm.ClassVisitor;
import net.bytebuddy.jar.asm.ClassWriter;
import net.bytebuddy.jar.asm.Opcodes;
/**
* @author ReaJason
* @since 2025/2/25
*/
public class ClassBytesShrink {
public static byte[] shrink(byte[] bytes, boolean full) {
ClassReader cr = new ClassReader(bytes);
ClassWriter cw = new ClassWriter(0);
ClassVisitor cv = new ClassVisitor(Opcodes.ASM9, cw) {
@Override
public void visitSource(String source, String debug) {
}
};
cr.accept(cv, full ? ClassReader.SKIP_DEBUG : 0);
return cw.toByteArray();
}
}