blob: c2e2b2efed71ae79d5b3580efc2287ef58419336 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.jdk.core.util.io.streams;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* @author Jeff C. Phillips
*/
public class StreamCatcher extends Thread {
private InputStream is;
private String type;
private Logger logger;
public StreamCatcher(InputStream is, String type) {
this(is, type, null);
}
public StreamCatcher(InputStream is, String type, Logger logger) {
this.is = is;
this.type = type;
this.logger = logger;
}
public void run() {
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
String loggerError = "";
while ((line = br.readLine()) != null) {
if (logger == null)
System.out.println(type + ">" + line);
else
loggerError += line + "\n";
}
if (logger != null && loggerError.length() > 0) logger.log(Level.SEVERE, loggerError);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
|