KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > logging > TCStreamLogger


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.logging;
5
6 import com.tc.util.Assert;
7
8 import java.io.BufferedReader JavaDoc;
9 import java.io.IOException JavaDoc;
10 import java.io.InputStream JavaDoc;
11 import java.io.InputStreamReader JavaDoc;
12
13 /**
14  * A simple thread that copies one stream to another. Useful for copying a process's output/error streams to this
15  * process's output/error streams.
16  */

17 public class TCStreamLogger extends Thread JavaDoc {
18
19   protected final BufferedReader JavaDoc in;
20   protected final TCLogger out;
21   protected final LogLevel level;
22
23   public TCStreamLogger(InputStream JavaDoc stream, TCLogger logger, LogLevel level) {
24     Assert.assertNotNull(stream);
25
26     this.in = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(stream));
27     this.out = logger;
28     this.level = level;
29   }
30
31   public void run() {
32     String JavaDoc line;
33     try {
34       while ((line = in.readLine()) != null) {
35         out.log(level, line);
36       }
37     } catch (IOException JavaDoc e) {
38       out.log(level, "Exception reading InputStream: " + e);
39     }
40   }
41
42 }
Popular Tags