KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.ProjectComponent;
25 import org.apache.tools.ant.Task;
26 import org.apache.tools.ant.util.LineOrientedOutputStream;
27
28 /**
29  * Logs each line written to this stream to the log system of ant.
30  *
31  * Tries to be smart about line separators.<br>
32  *
33  * @since Ant 1.2
34  */

35 public class LogOutputStream extends LineOrientedOutputStream {
36
37     private ProjectComponent pc;
38     private int level = Project.MSG_INFO;
39
40     /**
41      * Creates a new instance of this class.
42      *
43      * @param task the task for whom to log
44      * @param level loglevel used to log data written to this stream.
45      */

46     public LogOutputStream(Task task, int level) {
47         this((ProjectComponent) task, level);
48     }
49
50     /**
51      * Creates a new instance of this class.
52      *
53      * @param pc the project component for whom to log
54      * @param level loglevel used to log data written to this stream.
55      * @since Ant 1.6.3
56      */

57     public LogOutputStream(ProjectComponent pc, int level) {
58         this.pc = pc;
59         this.level = level;
60     }
61
62     /**
63      * Converts the buffer to a string and sends it to <code>processLine</code>
64      */

65     protected void processBuffer() {
66         try {
67             super.processBuffer();
68         } catch (IOException JavaDoc e) {
69             // impossible since *our* processLine doesn't throw an IOException
70
throw new RuntimeException JavaDoc("Impossible IOException caught: " + e);
71         }
72     }
73
74     /**
75      * Logs a line to the log system of ant.
76      *
77      * @param line the line to log.
78      */

79     protected void processLine(String JavaDoc line) {
80         processLine(line, level);
81     }
82
83     /**
84      * Logs a line to the log system of ant.
85      *
86      * @param line the line to log.
87      * @param level the logging level to use.
88      */

89     protected void processLine(String JavaDoc line, int level) {
90         pc.log(line, level);
91     }
92
93     /**
94      * Get the level.
95      * @return the log level.
96      */

97     public int getMessageLevel() {
98         return level;
99     }
100
101 }
102
Popular Tags