KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > jarprocessor > StreamProcessor


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.internal.jarprocessor;
12
13 import java.io.BufferedReader JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.io.InputStream JavaDoc;
16 import java.io.InputStreamReader JavaDoc;
17
18 public class StreamProcessor extends Thread JavaDoc {
19     public static final String JavaDoc STDERR = "STDERR"; //$NON-NLS-1$
20
public static final String JavaDoc STDOUT = "STDOUT"; //$NON-NLS-1$
21

22     private InputStream JavaDoc inputStream;
23     private String JavaDoc name;
24     private boolean verbose;
25
26     public StreamProcessor(InputStream JavaDoc is, String JavaDoc name, boolean verbose) {
27         this.inputStream = is;
28         this.name = name;
29         this.verbose = verbose;
30     }
31
32     public void run() {
33         try {
34             InputStreamReader JavaDoc isr = new InputStreamReader JavaDoc(inputStream);
35             BufferedReader JavaDoc br = new BufferedReader JavaDoc(isr);
36             while (true) {
37                 String JavaDoc s = br.readLine();
38                 if (s == null) {
39                     break;
40                 }
41                 if (verbose) {
42                     if (STDERR.equals(name))
43                         System.err.println(name + ": " + s); //$NON-NLS-1$
44
else
45                         System.out.println(name + ": " + s); //$NON-NLS-1$
46
}
47             }
48         } catch (IOException JavaDoc e) {
49             e.printStackTrace();
50         }
51     }
52
53 }
54
Popular Tags