/[classpath]/classpath/java/io/PrintStream.java
ViewVC logotype

Diff of /classpath/java/io/PrintStream.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by arenn, Sat Mar 15 23:08:05 2003 UTC revision 1.7 by mkoch, Sun Mar 23 10:53:30 2003 UTC
# Line 39  exception statement from your version. * Line 39  exception statement from your version. *
39  package java.io;  package java.io;
40    
41  /**  /**
42    * This class prints Java primitive values and object to a stream as   * This class prints Java primitive values and object to a stream as
43    * text.  None of the methods in this class throw an exception.  However,   * text.  None of the methods in this class throw an exception.  However,
44    * errors can be detected by calling the <code>checkError()</code> method.   * errors can be detected by calling the <code>checkError()</code> method.
45    * Additionally, this stream can be designated as "autoflush" when   * Additionally, this stream can be designated as "autoflush" when
46    * created so that any writes are automatically flushed to the underlying   * created so that any writes are automatically flushed to the underlying
47    * output sink when the current line is terminated.   * output sink when the current line is terminated.
48    * <p>   * <p>
49    * <b>Note that this class is deprecated</b>.  It exists for backward     * <b>Note that this class is deprecated</b>.  It exists for backward  
50    * compatibility only.  New code should be written to use   * compatibility only.  New code should be written to use
51    * <code>PrintWriter</code> instead.     * <code>PrintWriter</code> instead.  
52    * <p>   * <p>
53    * This class converts char's into byte's using the system default encoding.   * This class converts char's into byte's using the system default encoding.
54    *   *
55    * @deprecated   * @deprecated
56    *   *
57    * @author Aaron M. Renn (arenn@urbanophile.com)   * @author Aaron M. Renn (arenn@urbanophile.com)
58    */   */
59  public class PrintStream extends FilterOutputStream  public class PrintStream extends FilterOutputStream
60  {  {
61    
# Line 69  public class PrintStream extends FilterO Line 69  public class PrintStream extends FilterO
69     * encoding is done automagicially by the PrintWriter tree!     * encoding is done automagicially by the PrintWriter tree!
70     */     */
71    
   /*************************************************************************/  
   
   /*  
    * Instance Variables  
    */  
   
72    /**    /**
73      * This boolean indicates whether or not an error has ever occured     * This boolean indicates whether or not an error has ever occured
74      * on this stream.     * on this stream.
75      */     */
76    private boolean error_occurred;    private boolean error_occurred;
77    
78    /**    /**
79      * This is <code>true</code> if auto-flush is enabled,     * This is <code>true</code> if auto-flush is enabled,
80      * <code>false</code> otherwise     * <code>false</code> otherwise
81      */     */
82    private boolean auto_flush;    private boolean auto_flush;
83    
84    /**    /**
85      * The PrintWriter instance this object writes to     * The PrintWriter instance this object writes to
86      */     */
87    private PrintWriter pw;    private PrintWriter pw;
88    
89    /**    /**
90      * Lets us know if the stream is closed     * Lets us know if the stream is closed
     */  
   private boolean closed;  
   
   /*************************************************************************/  
   
   /*  
    * Constructors  
91     */     */
92      private boolean closed;
93    
94    /**    /**
95      * This method intializes a new <code>PrintStream</code> object to write     * This method intializes a new <code>PrintStream</code> object to write
96      * to the specified output sink.  Note that this class is deprecated in     * to the specified output sink.  Note that this class is deprecated in
97      * favor of <code>PrintWriter</code>.     * favor of <code>PrintWriter</code>.
98      *     *
99      * @param out The <code>OutputStream</code> to write to.     * @param out The <code>OutputStream</code> to write to.
100      *     *
101      * @deprecated     * @deprecated
102      */     */
103    public PrintStream(OutputStream out)    public PrintStream(OutputStream out)
104    {    {
105      this(out, false);      this(out, false);
106    }    }
107    
   /*************************************************************************/  
   
108    /**    /**
109      * This method intializes a new <code>PrintStream</code> object to write     * This method intializes a new <code>PrintStream</code> object to write
110      * to the specified output sink.  This constructor also allows "auto-flush"     * to the specified output sink.  This constructor also allows "auto-flush"
111      * functionality to be specified where the stream will be flushed after     * functionality to be specified where the stream will be flushed after
112      * every line is terminated or newline character is written.     * every line is terminated or newline character is written.
113      * <p>     * <p>
114      * Note that this class is deprecated in favor of <code>PrintWriter</code>.     * Note that this class is deprecated in favor of <code>PrintWriter</code>.
115      *     *
116      * @param out The <code>OutputStream</code> to write to.     * @param out The <code>OutputStream</code> to write to.
117      * @param auto_flush <code>true</code> to flush the stream after every     * @param auto_flush <code>true</code> to flush the stream after every
118      * line, <code>false</code> otherwise     * line, <code>false</code> otherwise
119      *     *
120      * @deprecated     * @deprecated
121      */     */
122    public PrintStream(OutputStream out, boolean auto_flush)    public PrintStream(OutputStream out, boolean auto_flush)
123    {    {
124      super(out);      super(out);
# Line 141  public class PrintStream extends FilterO Line 127  public class PrintStream extends FilterO
127      this.auto_flush = auto_flush;      this.auto_flush = auto_flush;
128    }    }
129    
   /*************************************************************************/  
   
130    /**    /**
131      * This method intializes a new <code>PrintStream</code> object to write     * This method intializes a new <code>PrintStream</code> object to write
132      * to the specified output sink.  This constructor also allows "auto-flush"     * to the specified output sink.  This constructor also allows "auto-flush"
133      * functionality to be specified where the stream will be flushed after     * functionality to be specified where the stream will be flushed after
134      * every line is terminated or newline character is written.     * every line is terminated or newline character is written.
135      * <p>     * <p>
136      * Note that this class is deprecated in favor of <code>PrintWriter</code>.     * Note that this class is deprecated in favor of <code>PrintWriter</code>.
137      *     *
138      * @param out The <code>OutputStream</code> to write to.     * @param out The <code>OutputStream</code> to write to.
139      * @param autoFlush <code>true</code> to flush the stream after every     * @param autoFlush <code>true</code> to flush the stream after every
140      * line, <code>false</code> otherwise     * line, <code>false</code> otherwise
141      * @param encoding The name of the character encoding to use for this     * @param encoding The name of the character encoding to use for this
142      * object.     * object.
143      *     *
144      * @deprecated     * @deprecated
145      */     */
146    public PrintStream(OutputStream out, boolean autoFlush, String encoding)    public PrintStream(OutputStream out, boolean autoFlush, String encoding)
147      throws UnsupportedEncodingException      throws UnsupportedEncodingException
148    {    {
# Line 168  public class PrintStream extends FilterO Line 152  public class PrintStream extends FilterO
152      this.auto_flush = autoFlush;      this.auto_flush = autoFlush;
153    }    }
154    
   /*************************************************************************/  
   
   /*  
    * Instance Methods  
    */  
   
155    /**    /**
156      * This method checks to see if an error has occurred on this stream.  Note     * This method checks to see if an error has occurred on this stream.  Note
157      * that once an error has occurred, this method will continue to report     * that once an error has occurred, this method will continue to report
158      * <code>true</code> forever for this stream.  Before checking for an     * <code>true</code> forever for this stream.  Before checking for an
159      * error condition, this method flushes the stream.     * error condition, this method flushes the stream.
160      *     *
161      * @return <code>true</code> if an error has occurred,     * @return <code>true</code> if an error has occurred,
162      * <code>false</code> otherwise     * <code>false</code> otherwise
163      */     */
164    public boolean checkError()    public boolean checkError()
165    {    {
166      if (!closed)      if (!closed)
# Line 194  public class PrintStream extends FilterO Line 172  public class PrintStream extends FilterO
172        return(false);        return(false);
173    }    }
174    
   /*************************************************************************/  
   
175    /**    /**
176      * This method can be called by subclasses to indicate that an error     * This method can be called by subclasses to indicate that an error
177      * has occurred and should be reported by <code>checkError</code>.     * has occurred and should be reported by <code>checkError</code>.
178      */     */
179    protected void setError()    protected void setError()
180    {    {
181      error_occurred = true;      error_occurred = true;
182    }    }
183            
   /*************************************************************************/  
   
184    /**    /**
185      * This method closes this stream and all underlying streams.     * This method closes this stream and all underlying streams.
186      */     */
187    public synchronized void close()    public synchronized void close()
188    {    {
189      pw.close();      pw.close();
190      closed = true;      closed = true;
191    }    }
192    
   /*************************************************************************/  
   
193    /**    /**
194      * This method flushes any buffered bytes to the underlying stream and     * This method flushes any buffered bytes to the underlying stream and
195      * then flushes that stream as well.     * then flushes that stream as well.
196      */     */
197    public void flush()    public void flush()
198    {    {
199      pw.flush();      pw.flush();
200    }    }
201    
   /*************************************************************************/  
   
202    /**    /**
203      * This methods prints a boolean value to the stream.  <code>true</code>     * This methods prints a boolean value to the stream.  <code>true</code>
204      * values are printed as "true" and <code>false</code> values are printed     * values are printed as "true" and <code>false</code> values are printed
205      * as "false".     * as "false".
206      *     *
207      * @param b The <code>boolean</code> value to print     * @param b The <code>boolean</code> value to print
208      */     */
209    public void print(boolean b)    public void print(boolean b)
210    {    {
211      pw.print(b);      pw.print(b);
212    }    }
213    
   /*************************************************************************/  
   
214    /**    /**
215      * This method prints a char to the stream.  The actual value printed is     * This method prints a char to the stream.  The actual value printed is
216      * determined by the character encoding in use.     * determined by the character encoding in use.
217      *     *
218      * @param c The <code>char</code> value to be printed     * @param c The <code>char</code> value to be printed
219      */     */
220    public void print(char c)    public void print(char c)
221    {    {
222      pw.print(c);      pw.print(c);
# Line 258  public class PrintStream extends FilterO Line 226  public class PrintStream extends FilterO
226          flush();              flush();    
227    }    }
228    
   /*************************************************************************/  
   
229    /**    /**
230      * This method prints an integer to the stream.  The value printed is     * This method prints an integer to the stream.  The value printed is
231      * determined using the <code>String.valueOf()</code> method.     * determined using the <code>String.valueOf()</code> method.
232      *     *
233      * @param i The <code>int</code> value to be printed     * @param i The <code>int</code> value to be printed
234      */     */
235    public void print(int i)    public void print(int i)
236    {    {
237      pw.print(i);      pw.print(i);
238    }    }
239    
   /*************************************************************************/  
   
240    /**    /**
241      * This method prints a long to the stream.  The value printed is     * This method prints a long to the stream.  The value printed is
242      * determined using the <code>String.valueOf()</code> method.     * determined using the <code>String.valueOf()</code> method.
243      *     *
244      * @param l The <code>long</code> value to be printed     * @param l The <code>long</code> value to be printed
245      */     */
246    public void print(long l)    public void print(long l)
247    {    {
248      pw.print(l);      pw.print(l);
249    }    }
250    
   /*************************************************************************/  
   
251    /**    /**
252      * This method prints a float to the stream.  The value printed is     * This method prints a float to the stream.  The value printed is
253      * determined using the <code>String.valueOf()</code> method.     * determined using the <code>String.valueOf()</code> method.
254      *     *
255      * @param f The <code>float</code> value to be printed     * @param f The <code>float</code> value to be printed
256      */     */
257    public void print(float f)    public void print(float f)
258    {    {
259      pw.print(f);      pw.print(f);
260    }    }
261    
   /*************************************************************************/  
   
262    /**    /**
263      * This method prints a double to the stream.  The value printed is     * This method prints a double to the stream.  The value printed is
264      * determined using the <code>String.valueOf()</code> method.     * determined using the <code>String.valueOf()</code> method.
265      *     *
266      * @param d The <code>double</code> value to be printed     * @param d The <code>double</code> value to be printed
267      */     */
268    public void print(double d)    public void print(double d)
269    {    {
270      pw.print(d);      pw.print(d);
271    }    }
272    
   /*************************************************************************/  
   
273    /**    /**
274      * This method prints an array of characters to the stream.  The actual     * This method prints an array of characters to the stream.  The actual
275      * value printed depends on the system default encoding.     * value printed depends on the system default encoding.
276      *     *
277      * @param s The array of characters to print.     * @param s The array of characters to print.
278      */     */
279    public void print(char[] s)    public void print(char[] s)
280    {    {
281      pw.print(s);      pw.print(s);
# Line 331  public class PrintStream extends FilterO Line 289  public class PrintStream extends FilterO
289            }            }
290    }    }
291    
   /*************************************************************************/  
   
292    /**    /**
293      * This method prints a <code>String</code> to the stream.  The actual     * This method prints a <code>String</code> to the stream.  The actual
294      * value printed depends on the system default encoding.     * value printed depends on the system default encoding.
295      *     *
296      * @param s The <code>String</code> to print.     * @param s The <code>String</code> to print.
297      */     */
298    public void print(String s)    public void print(String s)
299    {    {
300      pw.print(s);      pw.print(s);
# Line 348  public class PrintStream extends FilterO Line 304  public class PrintStream extends FilterO
304          flush();          flush();
305    }    }
306    
   /*************************************************************************/  
   
307    /**    /**
308      * This method prints an <code>Object</code> to the stream.  The actual     * This method prints an <code>Object</code> to the stream.  The actual
309      * value printed is determined by calling the <code>String.valueOf()</code>     * value printed is determined by calling the <code>String.valueOf()</code>
310      * method.     * method.
311      *     *
312      * @param obj The <code>Object</code> to print.     * @param obj The <code>Object</code> to print.
313      */     */
314    public void print(Object obj)    public void print(Object obj)
315    {    {
316      // Don't call pw directly.  Convert to String so we scan for newline      // Don't call pw directly.  Convert to String so we scan for newline
# Line 364  public class PrintStream extends FilterO Line 318  public class PrintStream extends FilterO
318      print(String.valueOf(obj));      print(String.valueOf(obj));
319    }    }
320    
   /*************************************************************************/  
   
321    /**    /**
322      * This method prints a line separator sequence to the stream.  The value     * This method prints a line separator sequence to the stream.  The value
323      * printed is determined by the system property <xmp>line.separator</xmp>     * printed is determined by the system property <xmp>line.separator</xmp>
324      * and is not necessarily the Unix '\n' newline character.     * and is not necessarily the Unix '\n' newline character.
325      */     */
326    public void println()    public void println()
327    {    {
328      pw.println();      pw.println();
329    }    }
330    
   /*************************************************************************/  
   
331    /**    /**
332      * This methods prints a boolean value to the stream.  <code>true</code>     * This methods prints a boolean value to the stream.  <code>true</code>
333      * values are printed as "true" and <code>false</code> values are printed     * values are printed as "true" and <code>false</code> values are printed
334      * as "false".     * as "false".
335      * <p>     * <p>
336      * This method prints a line termination sequence after printing the value.     * This method prints a line termination sequence after printing the value.
337      *     *
338      * @param b The <code>boolean</code> value to print     * @param b The <code>boolean</code> value to print
339      */     */
340    public void println(boolean b)    public void println(boolean b)
341    {    {
342      pw.println(b);      pw.println(b);
343    }    }
344    
   /*************************************************************************/  
   
345    /**    /**
346      * This method prints a char to the stream.  The actual value printed is     * This method prints a char to the stream.  The actual value printed is
347      * determined by the character encoding in use.     * determined by the character encoding in use.
348      * <p>     * <p>
349      * This method prints a line termination sequence after printing the value.     * This method prints a line termination sequence after printing the value.
350      *     *
351      * @param c The <code>char</code> value to be printed     * @param c The <code>char</code> value to be printed
352      */     */
353    public void println(char c)    public void println(char c)
354    {    {
355      pw.println(c);      pw.println(c);
356    }    }
357    
   /*************************************************************************/  
   
358    /**    /**
359      * This method prints an integer to the stream.  The value printed is     * This method prints an integer to the stream.  The value printed is
360      * determined using the <code>String.valueOf()</code> method.     * determined using the <code>String.valueOf()</code> method.
361      * <p>     * <p>
362      * This method prints a line termination sequence after printing the value.     * This method prints a line termination sequence after printing the value.
363      *     *
364      * @param i The <code>int</code> value to be printed     * @param i The <code>int</code> value to be printed
365      */     */
366    public void println(int i)    public void println(int i)
367    {    {
368      pw.println(i);      pw.println(i);
369    }    }
370    
   /*************************************************************************/  
   
371    /**    /**
372      * This method prints a long to the stream.  The value printed is     * This method prints a long to the stream.  The value printed is
373      * determined using the <code>String.valueOf()</code> method.     * determined using the <code>String.valueOf()</code> method.
374      * <p>     * <p>
375      * This method prints a line termination sequence after printing the value.     * This method prints a line termination sequence after printing the value.
376      *     *
377      * @param l The <code>long</code> value to be printed     * @param l The <code>long</code> value to be printed
378      */     */
379    public void println(long l)    public void println(long l)
380    {    {
381      pw.println(l);      pw.println(l);
382    }    }
383    
   /*************************************************************************/  
   
384    /**    /**
385      * This method prints a float to the stream.  The value printed is     * This method prints a float to the stream.  The value printed is
386      * determined using the <code>String.valueOf()</code> method.     * determined using the <code>String.valueOf()</code> method.
387      * <p>     * <p>
388      * This method prints a line termination sequence after printing the value.     * This method prints a line termination sequence after printing the value.
389      *     *
390      * @param f The <code>float</code> value to be printed     * @param f The <code>float</code> value to be printed
391      */     */
392    public void println(float f)    public void println(float f)
393    {    {
394      pw.println(f);      pw.println(f);
395    }    }
396    
   /*************************************************************************/  
   
397    /**    /**
398      * This method prints a double to the stream.  The value printed is     * This method prints a double to the stream.  The value printed is
399      * determined using the <code>String.valueOf()</code> method.     * determined using the <code>String.valueOf()</code> method.
400      * <p>     * <p>
401      * This method prints a line termination sequence after printing the value.     * This method prints a line termination sequence after printing the value.
402      *     *
403      * @param d The <code>double</code> value to be printed     * @param d The <code>double</code> value to be printed
404      */     */
405    public void println(double d)    public void println(double d)
406    {    {
407      pw.println(d);      pw.println(d);
408    }    }
409    
   /*************************************************************************/  
   
410    /**    /**
411      * This method prints an array of characters to the stream.  The actual     * This method prints an array of characters to the stream.  The actual
412      * value printed depends on the system default encoding.     * value printed depends on the system default encoding.
413      * <p>     * <p>
414      * This method prints a line termination sequence after printing the value.     * This method prints a line termination sequence after printing the value.
415      *     *
416      * @param s The array of characters to print.     * @param s The array of characters to print.
417      */     */
418    public void println(char[] s)    public void println(char[] s)
419    {    {
420      pw.println(s);      pw.println(s);
421    }    }
422    
   /*************************************************************************/  
   
423    /**    /**
424      * This method prints a <code>String</code> to the stream.  The actual     * This method prints a <code>String</code> to the stream.  The actual
425      * value printed depends on the system default encoding.     * value printed depends on the system default encoding.
426      * <p>     * <p>
427      * This method prints a line termination sequence after printing the value.     * This method prints a line termination sequence after printing the value.
428      *     *
429      * @param s The <code>String</code> to print.     * @param s The <code>String</code> to print.
430      */     */
431    public void println(String s)    public void println(String s)
432    {    {
433      pw.println(s);      pw.println(s);
434    }    }
435    
   /*************************************************************************/  
   
436    /**    /**
437      * This method prints an <code>Object</code> to the stream.  The actual     * This method prints an <code>Object</code> to the stream.  The actual
438      * value printed is determined by calling the <code>String.valueOf()</code>     * value printed is determined by calling the <code>String.valueOf()</code>
439      * method.     * method.
440      * <p>     * <p>
441      * This method prints a line termination sequence after printing the value.     * This method prints a line termination sequence after printing the value.
442      *     *
443      * @param obj The <code>Object</code> to print.     * @param obj The <code>Object</code> to print.
444      */     */
445    public void println(Object obj)    public void println(Object obj)
446    {    {
447      pw.println(obj);      pw.println(obj);
448    }    }
449    
   /*************************************************************************/  
   
450    /**    /**
451      * This method writes a byte of data to the stream.  If auto-flush is     * This method writes a byte of data to the stream.  If auto-flush is
452      * enabled, printing a newline character will cause the stream to be     * enabled, printing a newline character will cause the stream to be
453      * flushed after the character is written.     * flushed after the character is written.
454      *     *
455      * @param b The byte to be written     * @param b The byte to be written
456      */     */
457    public synchronized void write(int b)    public synchronized void write(int b)
458    {    {
459      // Sigh, we actually have to implement this method. Flush first so that      // Sigh, we actually have to implement this method. Flush first so that
# Line 542  public class PrintStream extends FilterO Line 474  public class PrintStream extends FilterO
474        }        }
475    }    }
476        
   /*************************************************************************/  
   
477    /**    /**
478      * This method writes <code>len</code> bytes from the specified array     * This method writes <code>len</code> bytes from the specified array
479      * starting at index <code>offset</code> into the array.     * starting at index <code>offset</code> into the array.
480      *     *
481      * @param buf The array of bytes to write     * @param buf The array of bytes to write
482      * @param offset The index into the array to start writing from     * @param offset The index into the array to start writing from
483      * @param len The number of bytes to write     * @param len The number of bytes to write
484      */     */
485    public synchronized void write(byte[] buf, int offset, int len)    public synchronized void write(byte[] buf, int offset, int len)
486    {    {
487      // We actually have to implement this method too. Flush first so that      // We actually have to implement this method too. Flush first so that

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26