KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > core > output2 > ErrWriter


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * ErrWriter.java
21  *
22  * Created on May 9, 2004, 5:06 PM
23  */

24
25 package org.netbeans.core.output2;
26
27 import java.util.logging.Logger JavaDoc;
28 import org.openide.windows.OutputListener;
29 import org.openide.windows.OutputWriter;
30
31 import java.io.IOException JavaDoc;
32
33 /**
34  * Wrapper OutputWriter for the standard out which marks its lines as being
35  * stderr.
36  *
37  * @author Tim Boudreau
38  */

39 class ErrWriter extends OutputWriter {
40     private OutWriter wrapped;
41     private NbWriter parent;
42     /** Creates a new instance of ErrWriter */
43     ErrWriter(OutWriter wrapped, NbWriter parent) {
44         super (new OutWriter.DummyWriter());
45         this.wrapped = wrapped;
46         this.parent = parent;
47     }
48
49     synchronized void setWrapped (OutWriter wrapped) {
50         this.wrapped = wrapped;
51         closed = true;
52     }
53
54     public void println(String JavaDoc s, OutputListener l) throws java.io.IOException JavaDoc {
55         println(s, l, false);
56     }
57
58     public void println(String JavaDoc s, OutputListener l, boolean important) throws java.io.IOException JavaDoc {
59         closed = false;
60         synchronized (wrapped) {
61             wrapped.println (s, l, important);
62             ((AbstractLines) wrapped.getLines()).markErr();
63         }
64     }
65     
66     public void reset() throws IOException JavaDoc {
67         Logger.getAnonymousLogger().warning("Do not call reset() on the error io," +
68         " only on the output IO. Reset on the error io does nothing.");
69         closed = false;
70     }
71     
72     public void close() {
73         if (!closed) {
74             closed = true;
75             parent.notifyErrClosed();
76         }
77     }
78
79     boolean closed = true;
80     boolean isClosed() {
81         return closed;
82     }
83
84     public void flush() {
85         wrapped.flush();
86     }
87     
88     public boolean checkError() {
89         return wrapped.checkError();
90     }
91     
92     public void write(int c) {
93         closed = false;
94         synchronized (wrapped) {
95             wrapped.write(c);
96             ((AbstractLines) wrapped.getLines()).markErr();
97         }
98     }
99     
100     public void write(char buf[], int off, int len) {
101         closed = false;
102         synchronized (wrapped) {
103             wrapped.write(buf, off, len);
104             ((AbstractLines) wrapped.getLines()).markErr();
105         }
106     }
107     
108     public void write(String JavaDoc s, int off, int len) {
109         closed = false;
110         synchronized (wrapped) {
111             wrapped.write(s, off, len);
112             ((AbstractLines) wrapped.getLines()).markErr();
113         }
114     }
115     
116     public void println(boolean x) {
117         closed = false;
118         synchronized (wrapped) {
119             wrapped.println (x);
120             ((AbstractLines) wrapped.getLines()).markErr();
121         }
122     }
123
124     public void println(int x) {
125         closed = false;
126         synchronized (wrapped) {
127             wrapped.println(x);
128             ((AbstractLines) wrapped.getLines()).markErr();
129         }
130     }
131     
132     public void println(char x) {
133         closed = false;
134         synchronized (wrapped) {
135             wrapped.println(x);
136             ((AbstractLines) wrapped.getLines()).markErr();
137         }
138     }
139     
140     public void println(long x) {
141         closed = false;
142         synchronized (wrapped) {
143             wrapped.println(x);
144             ((AbstractLines) wrapped.getLines()).markErr();
145         }
146     }
147     
148     public void println(float x) {
149         closed = false;
150         synchronized (wrapped) {
151             wrapped.println(x);
152             ((AbstractLines) wrapped.getLines()).markErr();
153         }
154     }
155     
156     public void println(double x) {
157         closed = false;
158         synchronized (wrapped) {
159             wrapped.println(x);
160             ((AbstractLines) wrapped.getLines()).markErr();
161         }
162     }
163     
164     public void println(char x[]) {
165         closed = false;
166         synchronized (wrapped) {
167             wrapped.println(x);
168             ((AbstractLines) wrapped.getLines()).markErr();
169         }
170     }
171     
172     public void println(String JavaDoc x) {
173         closed = false;
174         synchronized (wrapped) {
175             wrapped.println(x);
176             ((AbstractLines) wrapped.getLines()).markErr();
177         }
178     }
179     
180     public void println(Object JavaDoc x) {
181         closed = false;
182         synchronized (wrapped) {
183             wrapped.println(x);
184             ((AbstractLines) wrapped.getLines()).markErr();
185         }
186     }
187
188     public void print(char[] s) {
189         closed = false;
190         synchronized (wrapped) {
191             wrapped.print(s);
192             ((AbstractLines) wrapped.getLines()).markErr();
193         }
194     }
195
196     public void print(Object JavaDoc obj) {
197         closed = false;
198         synchronized (wrapped) {
199             wrapped.print(obj);
200             ((AbstractLines) wrapped.getLines()).markErr();
201         }
202     }
203
204     public void print(char c) {
205         closed = false;
206         synchronized (wrapped) {
207             wrapped.print(c);
208             ((AbstractLines) wrapped.getLines()).markErr();
209         }
210     }
211
212     public void print(int i) {
213         closed = false;
214         synchronized (wrapped) {
215             wrapped.print(i);
216             ((AbstractLines) wrapped.getLines()).markErr();
217         }
218     }
219
220     public void print(String JavaDoc s) {
221         closed = false;
222         synchronized (wrapped) {
223             wrapped.print(s);
224             ((AbstractLines) wrapped.getLines()).markErr();
225         }
226     }
227
228     public void print(boolean b) {
229         closed = false;
230         synchronized (wrapped) {
231             wrapped.print(b);
232             ((AbstractLines) wrapped.getLines()).markErr();
233         }
234     }
235     
236     public void println() {
237         closed = false;
238         synchronized (wrapped) {
239             wrapped.println();
240             ((AbstractLines) wrapped.getLines()).markErr();
241         }
242     }
243
244     
245 }
246
Popular Tags