1 emoticon source code
https://github.com/zly394/EmojiRegex/blob/master/src/main/java/com/zly/utils/EmojiRegexUtil.java
Copy the code
2 Test cases
import java.lang.instrument.Instrumentation; public class Main2 { public static void main(String[] args) { String text = "\uD83C\uDDF2\uD83C\uDDEA\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF 3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF 3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF 3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF 3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF 3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDE8\uD83C\uDDF3\uD83C\uDDEC\uD83C\uDDE 7\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73\uDB40\uDC7F\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC6 2\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74\uDB40\uDC7F\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC6 7\uDB40\uDC7F"; boolean allEmoji = EmojiUtil.isAllEmoji(text); System.out.println(allEmoji); } public static void premain(String args, Instrumentation inst) { inst.addTransformer(new MethodCallCountTransformer()); }} / / enhance the import org. Objectweb. Asm. ClassAdapter; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import java.lang.instrument.ClassFileTransformer; import java.lang.instrument.IllegalClassFormatException; import java.security.ProtectionDomain; public class MethodCallCountTransformer implements ClassFileTransformer { @Override public byte[] transform(ClassLoader loader, String className, Class<? > classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { try { if (!" java/util/regex/Pattern$CharProperty".equals(className) && !" java/util/regex/Pattern$BmpCharProperty".equals(className)) { return classfileBuffer; } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); ClassAdapter adapter = new MethodCallClassAdapter(writer, className); ClassReader reader = new ClassReader(classfileBuffer); reader.accept(adapter, 0); return writer.toByteArray(); }catch (Exception e){ return classfileBuffer; } } } // MethodCallClassAdapter import org.objectweb.asm.ClassAdapter; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.MethodVisitor; public class MethodCallClassAdapter extends ClassAdapter { private String className; Public CallClassAdapter(ClassVisitor CV, String className) {// next ClassVisitor of Responsechain, Here we pass in ClassWriter, and // take care of the output of super(CV) after rewriting the code; this.className = className; } // Override the visitMethod and define the MethodVisitor when the "operation" method is accessed, @override public MethodVisitor visitMethod(final int Access, final String name, final String desc, final String signature, final String[] exceptions) { MethodVisitor mv = cv.visitMethod(access, name, desc, signature,exceptions); MethodVisitor wrappedMv = mv; if (mv ! = null) {// For "operation" method if (name.equals("match")) {// Use custom MethodVisitor, WrappedMv = new CountCallMethodAdapter(name, mv); } } return wrappedMv; } } // MethodAdapter import org.objectweb.asm.MethodAdapter; import org.objectweb.asm.MethodVisitor; import org.objectweb.asm.Opcodes; public class CountCallMethodAdapter extends MethodAdapter { private String methodName; private String className; public CountCallMethodAdapter(MethodVisitor visitor, String className, String methodName) { super(visitor); this.methodName = methodName; this.className = className; } @Override public void visitCode() { visitMethodInsn(Opcodes.INVOKESTATIC, "com/you/gbrank/asm/counter/Counter", "printAndIncCount", "()V"); }}Copy the code
Class 3 Counter
import java.util.concurrent.atomic.AtomicInteger;
public class Counter {
private static AtomicInteger methodCallCount = new AtomicInteger(0);
public static void checkSecurity() {
System.out.println("SecurityChecker.checkSecurity ...");
//TODO real security check
}
public static void printAndIncCount() {
System.out.println(methodCallCount.incrementAndGet());
}
public static void printAndIncCount1(String className, String methodName) {
System.out.println(methodCallCount.get());
System.out.println(className + "." + methodName + " called, total times " + methodCallCount.incrementAndGet());
}
}
Copy the code
Results: 4
The enhancement had no effect and no logs were printed. MARK
5 Solutions:
Blog.csdn.net/qfzhangwei/… A solution is given