KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > remoting > TestCallable


1 package hudson.remoting;
2
3 import java.io.InputStream JavaDoc;
4 import java.io.ByteArrayOutputStream JavaDoc;
5
6 /**
7  * {@link Callable} used to verify the classloader used.
8  *
9  * @author Kohsuke Kawaguchi
10  */

11 public class TestCallable implements Callable {
12     public Object JavaDoc call() throws Throwable JavaDoc {
13         Object JavaDoc[] r = new Object JavaDoc[4];
14
15         // to verify that this class is indeed loaded by the remote classloader
16
r[0] = getClass().getClassLoader().toString();
17
18         // to make sure that we can also load resources
19
String JavaDoc resName = "TestCallable.class";
20         InputStream JavaDoc in = getClass().getResourceAsStream(resName);
21         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
22
23         byte[] buf = new byte[8192];
24         int len;
25         while((len=in.read(buf))>0)
26             baos.write(buf,0,len);
27         in.close();
28
29         r[1] = baos.toByteArray();
30
31         // to make sure multiple resource look ups are cached.
32
r[2] = getClass().getResource(resName);
33         r[3] = getClass().getResource(resName);
34
35         return r;
36     }
37
38 }
39
Popular Tags