Menu

[21d594]: / test / java / nginx / clojure / ClassVerifyTestMain.java  Maximize  Restore  History

Download this file

45 lines (37 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package nginx.clojure;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import nginx.clojure.wave.JavaAgent;
public class ClassVerifyTestMain {
public ClassVerifyTestMain() {
// TODO Auto-generated constructor stub
}
public static byte[] getClassBytes(String clz) throws IOException {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(clz + ".class");
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int c = 0;
while ((c = is.read(buf)) > 0) {
out.write(buf, 0 ,c);
}
out.flush();
is.close();
return out.toByteArray();
}
public static void main(String[] args) {
ClassFileTransformer cft = JavaAgent.buildClassFileTransformer("mbdp");
try {
String clz = args[0];
cft.transform(Thread.currentThread().getContextClassLoader(), clz, null, null, getClassBytes(clz));
} catch (IllegalClassFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.