01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant.taskdefs;
20:
21: import java.io.IOException;
22: import java.io.OutputStream;
23: import org.apache.tools.ant.Task;
24:
25: /**
26: * Redirects text written to a stream thru the standard
27: * ant logging mechanism. This class is useful for integrating
28: * with tools that write to System.out and System.err. For example,
29: * the following will cause all text written to System.out to be
30: * logged with "info" priority:
31: * <pre>System.setOut(new PrintStream(new TaskOutputStream(project, Project.MSG_INFO)));</pre>
32: *
33: * <p><strong>As of Ant 1.2, this class is considered to be dead code
34: * by the Ant developers and is unmaintained. Don't use
35: * it.</strong></p>
36: *
37: * @deprecated since 1.2.x.
38: * Use LogOutputStream instead.
39: */
40:
41: public class TaskOutputStream extends OutputStream {
42:
43: private Task task;
44: private StringBuffer line;
45: private int msgOutputLevel;
46:
47: /**
48: * Constructs a new JavacOutputStream with the given project
49: * as the output source for messages.
50: */
51:
52: TaskOutputStream(Task task, int msgOutputLevel) {
53: System.err
54: .println("As of Ant 1.2 released in October 2000, the "
55: + "TaskOutputStream class");
56: System.err.println("is considered to be dead code by the Ant "
57: + "developers and is unmaintained.");
58: System.err.println("Don\'t use it!");
59:
60: this .task = task;
61: this .msgOutputLevel = msgOutputLevel;
62:
63: line = new StringBuffer();
64: }
65:
66: /**
67: * Write a character to the output stream. This method looks
68: * to make sure that there isn't an error being reported and
69: * will flush each line of input out to the project's log stream.
70: * @param c the character to write
71: * @throws IOException on error
72: */
73:
74: public void write(int c) throws IOException {
75: char cc = (char) c;
76: if (cc == '\r' || cc == '\n') {
77: // line feed
78: if (line.length() > 0) {
79: processLine();
80: }
81: } else {
82: line.append(cc);
83: }
84: }
85:
86: /**
87: * Processes a line of input and determines if an error occurred.
88: */
89:
90: private void processLine() {
91: String s = line.toString();
92: task.log(s, msgOutputLevel);
93: line = new StringBuffer();
94: }
95: }
|