001 /*
002 * Err.java
003 *
004 * Copyright (c) 1995-2010, The University of Sheffield. See the file
005 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
006 *
007 * This file is part of GATE (see http://gate.ac.uk/), and is free
008 * software, licenced under the GNU Library General Public License,
009 * Version 2, June 1991 (in the distribution as file licence.html,
010 * and also available at http://gate.ac.uk/gate/licence.html).
011 *
012 * Cristian URSU, 29 September 2000
013 *
014 * $Id: Err.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015 */
016
017 package gate.util;
018
019 import java.io.PrintWriter;
020
021 /** Shorthand for the <CODE> System.err.print and println</CODE>
022 * methods.
023 */
024 public class Err {
025 /** Debug flag */
026 private static final boolean DEBUG = false;
027
028 /** A printwriter to delegate to */
029 private static PrintWriter err = new PrintWriter(System.err,true);
030
031 /** Don't construct any of these */
032 private Err() {}
033
034 /** Flush the output stream. */
035 public static void flush() { err.flush(); }
036
037 /** This sets a new printWriter*/
038 public static void setPrintWriter(PrintWriter aPrintWriter) {
039 err = aPrintWriter;
040 }//setPrintWriter
041
042 /** This sets a new printWriter*/
043 public static PrintWriter getPrintWriter() {
044 return err;
045 }
046
047 // print() and println() methods definition
048 ////////////////////////////////////////////////
049
050 /** @see java.io.PrintWriter#print(boolean) */
051 public static void print(boolean b) {
052 err.print(b);
053 err.flush();
054 }
055
056 /** @see java.io.PrintWriter#print(char) */
057 public static void print(char c) {
058 err.print(c);
059 err.flush();
060 }
061
062 /** @see java.io.PrintWriter#print(int) */
063 public static void print(int i) {
064 err.print(i);
065 err.flush();
066 }
067
068 /** @see java.io.PrintWriter#print(long) */
069 public static void print(long l) {
070 err.print(l);
071 err.flush();
072 }
073
074 /** @see java.io.PrintWriter#print(float) */
075 public static void print(float f) {
076 err.print(f);
077 err.flush();
078 }
079
080 /** @see java.io.PrintWriter#print(double) */
081 public static void print(double d) {
082 err.print(d);
083 err.flush();
084 }
085
086 /** @see java.io.PrintWriter#print(char[]) */
087 public static void print(char s[]) {
088 err.print(s);
089 err.flush();
090 }
091
092 /** @see java.io.PrintWriter#print(java.lang.String) */
093 public static void print(String s) {
094 err.print(s);
095 err.flush();
096 }
097
098 /** @see java.io.PrintWriter#print(java.lang.Object) */
099 public static void print(Object obj) {
100 err.print(obj);
101 err.flush();
102 }
103
104 /** @see java.io.PrintWriter#println() */
105 public static void println() {
106 err.println();
107 }
108
109 /** @see java.io.PrintWriter#println(boolean) */
110 public static void println(boolean x) {
111 err.println(x);
112 }
113
114 /** @see java.io.PrintWriter#println(char) */
115 public static void println(char x) {
116 err.println(x);
117 }
118
119 /** @see java.io.PrintWriter#println(int) */
120 public static void println(int x) {
121 err.println(x);
122 }
123
124 /** @see java.io.PrintWriter#println(long) */
125 public static void println(long x) {
126 err.println(x);
127 }
128
129 /** @see java.io.PrintWriter#println(float) */
130 public static void println(float x) {
131 err.println(x);
132 }
133
134 /** @see java.io.PrintWriter#println(double) */
135 public static void println(double x) {
136 err.println(x);
137 }
138
139 /** @see java.io.PrintWriter#println(char[]) */
140 public static void println(char x[]) {
141 err.println(x);
142 }
143
144 /** @see java.io.PrintWriter#println(java.lang.String) */
145 public static void println(String x) {
146 err.println(x);
147 }
148
149 /** @see java.io.PrintWriter#println(java.lang.Object) */
150 public static void println(Object x) {
151 err.println(x);
152 }
153
154 // pr and prln uses print and println so further modifications
155 // must be done to print and println only
156 ////////////////////////////////////////////////////////////////
157
158 /** @see java.io.PrintWriter#print(boolean) */
159 public static void pr(boolean b) {
160 print(b);
161 }
162
163 /** @see java.io.PrintWriter#print(char) */
164 public static void pr(char c) {
165 print(c);
166 }
167
168 /** @see java.io.PrintWriter#print(int) */
169 public static void pr(int i) {
170 print(i);
171 }
172
173 /** @see java.io.PrintWriter#print(long) */
174 public static void pr(long l) {
175 print(l);
176 }
177
178 /** @see java.io.PrintWriter#print(float) */
179 public static void pr(float f) {
180 print(f);
181 }
182
183 /** @see java.io.PrintWriter#print(double) */
184 public static void pr(double d) {
185 print(d);
186 }
187
188 /** @see java.io.PrintWriter#print(char[]) */
189 public static void pr(char s[]) {
190 print(s);
191 }
192
193 /** @see java.io.PrintWriter#print(java.lang.String) */
194 public static void pr(String s) {
195 print(s);
196 }
197
198 /** @see java.io.PrintWriter#print(java.lang.Object) */
199 public static void pr(Object obj) {
200 print(obj);
201 }
202
203 /** @see java.io.PrintWriter#println() */
204 public static void prln() {
205 println();
206 }
207
208 /** @see java.io.PrintWriter#println(boolean) */
209 public static void prln(boolean x) {
210 println(x);
211 }
212
213 /** @see java.io.PrintWriter#println(char) */
214 public static void prln(char x) {
215 println(x);
216 }
217
218 /** @see java.io.PrintWriter#println(int) */
219 public static void prln(int x) {
220 println(x);
221 }
222
223 /** @see java.io.PrintWriter#println(long) */
224 public static void prln(long x) {
225 println(x);
226 }
227
228 /** @see java.io.PrintWriter#println(float) */
229 public static void prln(float x) {
230 println(x);
231 }
232
233 /** @see java.io.PrintWriter#println(double) */
234 public static void prln(double x) {
235 println(x);
236 }
237
238 /** @see java.io.PrintWriter#println(char[]) */
239 public static void prln(char x[]) {
240 println(x);
241 }
242
243 /** @see java.io.PrintWriter#println(java.lang.String) */
244 public static void prln(String x) {
245 println(x);
246 }
247
248 /** @see java.io.PrintWriter#println(java.lang.Object) */
249 public static void prln(Object x) {
250 println(x);
251 }
252
253 /** Char to pad with. */
254 private static char padChar = ' ';
255
256 /** A mutator method for padChar*/
257 public static void setPadChar(char aChar){
258 padChar = aChar;
259 }//setPadChar
260
261 /** An accesor method for padChar*/
262 public static char getPadChar(){
263 return padChar;
264 }//getPadChar
265
266 /** Print padding followed by String s. */
267 public static void padPr(String s, int padding) {
268 for(int i=0; i<padding; i++)
269 err.print(padChar);
270 err.print(s);
271 err.flush();
272 } // padPr(String,int)
273
274 } //Err
|