diff options
author | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 1999-04-07 14:42:40 +0000 |
---|---|---|
committer | tromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4> | 1999-04-07 14:42:40 +0000 |
commit | 2c60951ba0efef23e2b765964b5dc0f1f49438a9 (patch) | |
tree | d96801a16fdf03a5682ef98730fe333a46eef944 /libjava/java/io/PrintStream.java | |
parent | 1135eed2207f8f82c589e42ce113a1c2f0310778 (diff) | |
download | ppe42-gcc-2c60951ba0efef23e2b765964b5dc0f1f49438a9.tar.gz ppe42-gcc-2c60951ba0efef23e2b765964b5dc0f1f49438a9.zip |
Initial revision
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@26263 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/io/PrintStream.java')
-rw-r--r-- | libjava/java/io/PrintStream.java | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/libjava/java/io/PrintStream.java b/libjava/java/io/PrintStream.java new file mode 100644 index 00000000000..499e5eb7059 --- /dev/null +++ b/libjava/java/io/PrintStream.java @@ -0,0 +1,236 @@ +// PrintStream.java - Print string representations + +/* Copyright (C) 1998, 1999 Cygnus Solutions + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package java.io; + +/** + * @author Tom Tromey <tromey@cygnus.com> + * @date September 24, 1998 + */ + +/* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 + * "The Java Language Specification", ISBN 0-201-63451-1 + * Status: Not finished. + */ + +public class PrintStream extends FilterOutputStream +{ + public boolean checkError () + { + return error; + } + + public void close () + { + try + { + out.close(); + } + catch (IOException e) + { + setError (); + } + } + + public void flush () + { + try + { + out.flush(); + } + catch (IOException e) + { + setError (); + } + } + + private final void print (String str, boolean check_term) + { + try + { + write(str.getBytes()); + if (check_term + && auto_flush + && str.indexOf(line_separator) != -1) + flush (); + } + catch (IOException e) + { + setError (); + } + } + + public void print (boolean bool) + { + print (String.valueOf(bool), false); + } + + public void print (int inum) + { + print (String.valueOf(inum), false); + } + + public void print (long lnum) + { + print (String.valueOf(lnum), false); + } + + public void print (float fnum) + { + print (String.valueOf(fnum), false); + } + + public void print (double dnum) + { + print (String.valueOf(dnum), false); + } + + public void print (Object obj) + { + print (String.valueOf(obj), false); + } + + public void print (String str) + { + print (str, true); + } + + public void print (char ch) + { + print (String.valueOf(ch), true); + } + + public void print (char[] charArray) + { + print (String.valueOf(charArray), true); + } + + public void println () + { + print (line_separator, false); + if (auto_flush) + flush (); + } + + public void println (boolean bool) + { + print (String.valueOf(bool), false); + println (); + } + + public void println (int inum) + { + print (String.valueOf(inum), false); + println (); + } + + public void println (long lnum) + { + print (String.valueOf(lnum), false); + println (); + } + + public void println (float fnum) + { + print (String.valueOf(fnum), false); + println (); + } + + public void println (double dnum) + { + print (String.valueOf(dnum), false); + println (); + } + + public void println (Object obj) + { + print (String.valueOf(obj), false); + println (); + } + + public void println (String str) + { + print (str, false); + println (); + } + + public void println (char ch) + { + print (String.valueOf(ch), false); + println (); + } + + public void println (char[] charArray) + { + print (String.valueOf(charArray), false); + println (); + } + + public PrintStream (OutputStream out) + { + super (out); + error = false; + auto_flush = false; + } + + public PrintStream (OutputStream out, boolean af) + { + super (out); + error = false; + auto_flush = af; + } + + protected void setError () + { + error = true; + } + + public void write (int oneByte) + { + try + { + out.write(oneByte); + // JCL says to do this. I think it is wrong. FIXME. + if (auto_flush && oneByte == '\n') + out.flush(); + } + catch (IOException e) + { + setError (); + } + } + + public void write (byte[] buffer, int offset, int count) + { + try + { + out.write(buffer, offset, count); + // FIXME: JCL says to flush. But elsewhere the JCL says to + // use write to write the stringified form of an object, and + // only to flush if that string contains the line separator. + // How to resolve the contradiction? + if (auto_flush) + out.flush(); + } + catch (IOException e) + { + setError (); + } + } + + // True if error occurred. + private boolean error; + // True if auto-flush. + private boolean auto_flush; + + // Line separator string. + private static final String line_separator + = System.getProperty("line.separator"); +} |