01: /*
02: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05: package com.sun.portal.monitoring.utilities;
06:
07: import java.io.IOException;
08: import java.io.InputStream;
09:
10: public class ProcessStreamReader extends Thread {
11: private InputStream is = null;
12: private Boolean isError = Boolean.TRUE;
13:
14: public ProcessStreamReader(InputStream is, Boolean isError) {
15: this .is = is;
16: this .isError = isError;
17: }
18:
19: private void writeDebug(byte[] oneByte, byte[] buffer) {
20: if (isError.booleanValue()) {
21: // System.err.println("Command error <" + new String(oneByte) + new String(buffer) + ">");
22: } else {
23: // System.out.println("Command output <" + new String(oneByte) + new String(buffer) + ">");
24: }
25: }
26:
27: public void run() {
28: try {
29: do {
30: int oneByte = is.read();
31: if (oneByte == -1)
32: break;
33:
34: int avail = is.available();
35: byte[] buffer = new byte[avail];
36: int count = is.read(buffer);
37: if (count == -1)
38: break;
39:
40: writeDebug(new byte[] { (byte) oneByte }, buffer);
41: } while (true);
42:
43: is.close();
44: } catch (IOException ioe) {
45: // ioe.printStackTrace();
46: }
47: }
48: }
|