KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > TaskOutputStream


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
22 import java.io.OutputStream JavaDoc;
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 JavaDoc {
42
43     private Task task;
44     private StringBuffer JavaDoc 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.println("As of Ant 1.2 released in October 2000, the "
54             + "TaskOutputStream class");
55         System.err.println("is considered to be dead code by the Ant "
56             + "developers and is unmaintained.");
57         System.err.println("Don\'t use it!");
58
59         this.task = task;
60         this.msgOutputLevel = msgOutputLevel;
61
62         line = new StringBuffer JavaDoc();
63     }
64
65     /**
66      * Write a character to the output stream. This method looks
67      * to make sure that there isn't an error being reported and
68      * will flush each line of input out to the project's log stream.
69      * @param c the character to write
70      * @throws IOException on error
71      */

72
73     public void write(int c) throws IOException JavaDoc {
74         char cc = (char) c;
75         if (cc == '\r' || cc == '\n') {
76             // line feed
77
if (line.length() > 0) {
78                 processLine();
79             }
80         } else {
81             line.append(cc);
82         }
83     }
84
85     /**
86      * Processes a line of input and determines if an error occurred.
87      */

88
89     private void processLine() {
90         String JavaDoc s = line.toString();
91         task.log(s, msgOutputLevel);
92         line = new StringBuffer JavaDoc();
93     }
94 }
95
96
Popular Tags