01: /*
02: * Copyright 2000,2002-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: *
16: */
17:
18: package com.openedit.modules.update;
19:
20: import java.io.BufferedReader;
21: import java.io.IOException;
22: import java.io.InputStream;
23: import java.io.InputStreamReader;
24: import java.io.OutputStream;
25:
26: /**
27: * This class was swiped from ant.
28: */
29: public class StreamPumper extends Thread {
30: private BufferedReader din;
31: private boolean endOfStream = false;
32: private int SLEEP_TIME = 5;
33: private OutputStream fieldOutputStream;
34:
35: public StreamPumper(InputStream is, OutputStream os) {
36: this .din = new BufferedReader(new InputStreamReader(is));
37: fieldOutputStream = os;
38: }
39:
40: public void pumpStream() throws IOException {
41: if (!endOfStream) {
42: String line = din.readLine();
43:
44: if (line != null) {
45: getOutputStream().write(line.getBytes());
46:
47: } else {
48: endOfStream = true;
49: }
50: }
51: }
52:
53: public void run() {
54: try {
55: try {
56: while (!endOfStream) {
57: pumpStream();
58: sleep(SLEEP_TIME);
59: }
60: } catch (InterruptedException ie) {
61: //ignore
62: }
63: din.close();
64: } catch (IOException ioe) {
65: // ignore
66: }
67: }
68:
69: protected OutputStream getOutputStream() {
70: return fieldOutputStream;
71: }
72: }
|