KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ExtractorProcessOutputReader


1 /* $Id$
2  *
3  * Copyright (c) 1998 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  *
15  * FIXME:
16  */

17
18
19 // Extractor.java
20

21 // Description:
22
// A class to extract the package file into the current directory.
23
//
24
// Author:
25
// Peter Pilgrim
26
// Wed Feb 10 05:51:34 GMT 1999
27
//
28
// RCS HEADER
29
//
30
// $Author$
31
// $Date$
32
// $Source$
33
// $Revision$ $State$ $Locker$
34
//
35
// History
36
// ================================================================================
37
// $Log$
38

39
40 import java.io.*; // for File I/O Classes
41

42 /**
43  * A threadable object which continuously read data from an
44  * input stream and outputs it to a particular <code>PrintStream</code>.
45  */

46 public class ExtractorProcessOutputReader
47 implements Runnable JavaDoc
48 {
49     protected BufferedReader reader;
50     protected PrintStream out;
51     
52     public ExtractorProcessOutputReader( InputStream input_stream,
53                      PrintStream out )
54     {
55     // Use a buffered reader to read N characters efficiently
56
// at a time.
57
reader = new BufferedReader( new InputStreamReader( input_stream ));
58     this.out = out;
59     }
60     
61     public void run()
62     {
63     // Thread execution
64
try {
65         // System.out.println("DEBUG: ExtractorProcessOutputReader thread started ...");
66

67         String JavaDoc line;
68         
69         while ( (line = reader.readLine()) != null )
70         {
71         out.println( line);
72         }
73     }
74     catch (IOException e) { // 2
75
System.err.println(e);
76     }
77     // System.out.println("DEBUG: ExtractorProcessOutputReader thread exiting ...");
78
}
79     
80     /** safe finalize method */
81     public void finalize()
82     throws Throwable JavaDoc
83     {
84     // System.out.println("DEBUG: ExtractorProcessOutputReader.finalize() ...");
85
try {
86         if (reader != null) {
87         out.flush(); /*1*/
88         reader.close(); /*2*/
89         reader = null; /*3*/
90         }
91     }
92     catch (IOException ioe) {
93     }
94     finally {
95         super.finalize(); // ALWAYS chain finalize methods
96
}
97     }
98 }
99
100 // fini
101

102
103
Popular Tags