KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > uka > ipd > coverage > utils > ByteCodePrinterThread


1 /*
2  * Created on 16.12.2004
3  *
4  * written by Matthias Kempka
5  */

6 package de.uka.ipd.coverage.utils;
7
8 import java.io.*;
9
10 import org.apache.bcel.classfile.Code;
11
12
13 /**
14  * Created on 16.12.2004<br>
15  * This class uses the class de.uka.ipd.coverage.utils.ByteCodePrinter to
16  * print human-readable bytecode to a reader, one instruction per line.
17  * The reader can be fetched from a
18  * ByteCodePrinterThread object after instanciating and before starting the
19  * thread via the getReader() method.<br>
20  * See ByteCodePrinter.printByteCode() for an example usage of
21  * this class.
22  * @author Matthias Kempka
23  */

24 /*
25  * This method using a thread is somewhat cumbersome, but necessary since
26  * it uses PipedInputStream and PipedOutputStream and it is recommended
27  * to use the different Streams in different threads.
28  */

29 class ByteCodePrinterThread extends Thread JavaDoc {
30
31     private PrintStream out;
32     private String JavaDoc id;
33     private Code code;
34     private BufferedReader reader;
35     
36     
37     
38     public ByteCodePrinterThread(Code code) {
39         super();
40         this.code = code;
41         PipedInputStream in = new PipedInputStream();
42         reader = new BufferedReader(new InputStreamReader(in));
43         try {
44             out = new PrintStream(new PipedOutputStream(in));
45         } catch (IOException e) {
46             e.printStackTrace();
47         }
48     }
49     
50     
51     public void run() {
52         ByteCodePrinter.printByteCode(out, null, code, false, false);
53         out.flush();
54         out.close();
55     }
56     
57     public BufferedReader getReader() {
58         return reader;
59     }
60 }
61
Popular Tags