aboutsummaryrefslogtreecommitdiffstats
path: root/sample/hotswap/Test.java
blob: e15afc9a578861e6cfe44ba7fe7dffa381b1730b (plain)
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
import java.io.*;
import javassist.tools.HotSwapper;

public class Test {
    public static void main(String[] args) throws Exception {
        HotSwapper hs = new HotSwapper(8000);
        new HelloWorld().print();

        File newfile = new File("logging/HelloWorld.class");
        byte[] bytes = new byte[(int)newfile.length()];
        new FileInputStream(newfile).read(bytes);
        System.out.println("** reload a logging version");

        hs.reload("HelloWorld", bytes);
        new HelloWorld().print();

        newfile = new File("HelloWorld.class");
        bytes = new byte[(int)newfile.length()];
        new FileInputStream(newfile).read(bytes);
        System.out.println("** reload the original version");

        hs.reload("HelloWorld", bytes);
        new HelloWorld().print();
    }
}