This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: java.io.PrintStream


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


the attached patch simplifies java.io.PrintStream a bit. It does not 
solve the current problem with the mauve testcase 
PrintStream.subclass. This will be addressed in a forthcoming patch.

Please review and comment.


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+7y/vWSOgCCdjSDsRAhPJAKCXAwH6eZfEu7S3bG6V5uFL6/33jQCfTgiA
upul7uaqoXvioa+76ZgRHl4=
=mGXz
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1953
diff -u -b -B -r1.1953 ChangeLog
--- ChangeLog	17 Jun 2003 14:16:21 -0000	1.1953
+++ ChangeLog	17 Jun 2003 15:07:22 -0000
@@ -1,5 +1,17 @@
 2003-06-17  Michael Koch  <konqueror@gmx.de>
 
+	* java/io/PrintStream.java
+	(lineSeparator): New static member variable.
+	(checkError): Call flush() instead of direct flushing of the Writer
+	object.
+	(print): Call print(String) instead of direct print method of the
+	Writer Object.
+	(println): Call println(String) instead of direct println method of the
+	Writer Object.
+	(write): Simplified.
+
+2003-06-17  Michael Koch  <konqueror@gmx.de>
+
 	* java/util/Locale.java
 	(getDisplayLanguage): Made it final.
 	(getDisplayCountry): Likewise.
Index: java/io/PrintStream.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/PrintStream.java,v
retrieving revision 1.20
diff -u -b -B -r1.20 PrintStream.java
--- java/io/PrintStream.java	12 Jun 2003 03:13:14 -0000	1.20
+++ java/io/PrintStream.java	17 Jun 2003 15:07:22 -0000
@@ -58,16 +58,10 @@
  */
 public class PrintStream extends FilterOutputStream
 {
-  /*
-   * This class could easily have been extended to support character
-   * encodings.  In fact, PrintWriter is basically a superset of this
-   * except for the write() methods.  So let's do something tricky
-   * here and just redirect calls in this class to a hidden
-   * PrintWriter instance.  All the functionality goes there since
-   * that is the 'real' class.  The big win of doing this way is that
-   * the default character encoding is done automagicially by the
-   * PrintWriter tree!
+  /**
+   * This holds the native line separator.
    */
+  private static final String lineSeparator = System.getProperty ("line.separator");
 
   /**
    * This boolean indicates whether or not an error has ever occurred
@@ -155,7 +149,7 @@
   public boolean checkError ()
   {
     if (!closed)
-      pw.flush ();
+      flush ();
 
     return error_occurred | pw.checkError ();
   }
@@ -196,7 +190,7 @@
    */
   public void print (boolean bool)
   {
-    pw.print (bool);
+    print (String.valueOf (bool));
   }
 
   /**
@@ -207,7 +201,7 @@
    */
   public void print (int inum)
   {
-    pw.print (inum);
+    print (String.valueOf (inum));
   }
 
   /**
@@ -218,7 +212,7 @@
    */
   public void print (long lnum)
   {
-    pw.print (lnum);
+    print (String.valueOf (lnum));
   }
 
   /**
@@ -229,7 +223,7 @@
    */
   public void print (float fnum)
   {
-    pw.print (fnum);
+    print (String.valueOf (fnum));
   }
 
   /**
@@ -240,7 +234,7 @@
    */
   public void print (double dnum)
   {
-    pw.print (dnum);
+    print (String.valueOf (dnum));
   }
 
   /**
@@ -281,12 +275,7 @@
    */
   public void print (char ch)
   {
-    pw.print (ch);
-
-    if (auto_flush)
-      if ((ch == '\r')
-          || (ch == '\n'))
-        flush ();    
+    print (String.valueOf (ch));
   }
 
   /**
@@ -297,16 +286,7 @@
    */
   public void print (char[] charArray)
   {
-    pw.print (charArray);
-
-    if (auto_flush)
-      for (int i = 0; i < charArray.length; i++)
-        if ((charArray [i] == '\r')
-            || (charArray [i] == '\n'))
-          {
-            flush ();
-            break;
-          }
+    print (String.valueOf (charArray));
   }
 
   /**
@@ -316,7 +296,7 @@
    */
   public void println ()
   {
-    pw.println ();
+    print (lineSeparator);
   }
 
   /**
@@ -330,7 +310,7 @@
    */
   public void println (boolean bool)
   {
-    pw.println (bool);
+    println (String.valueOf (bool));
   }
 
   /**
@@ -343,7 +323,7 @@
    */
   public void println (int inum)
   {
-    pw.println (inum);
+    println (String.valueOf (inum));
   }
 
   /**
@@ -356,7 +336,7 @@
    */
   public void println (long lnum)
   {
-    pw.println (lnum);
+    println (String.valueOf (lnum));
   }
 
   /**
@@ -369,7 +349,7 @@
    */
   public void println (float fnum)
   {
-    pw.println (fnum);
+    println (String.valueOf (fnum));
   }
 
   /**
@@ -382,7 +362,7 @@
    */
   public void println (double dnum)
   {
-    pw.println (dnum);
+    println (String.valueOf (dnum));
   }
 
   /**
@@ -396,7 +376,7 @@
    */
   public void println (Object obj)
   {
-    pw.println (obj);
+    println (String.valueOf (obj));
   }
 
   /**
@@ -409,7 +389,8 @@
    */
   public void println (String str)
   {
-    pw.println (str);
+    print (str);
+    print (lineSeparator);
   }
 
   /**
@@ -422,7 +403,7 @@
    */
   public void println (char ch)
   {
-    pw.println (ch);
+    println (String.valueOf (ch));
   }
 
   /**
@@ -435,7 +416,7 @@
    */
   public void println (char[] charArray)
   {
-    pw.println (charArray);
+    println (String.valueOf (charArray));
   }
 
   /**
@@ -447,21 +428,9 @@
    */
   public void write (int oneByte)
   {
-    // Sigh, we actually have to implement this method. Flush first so that
-    // things get written in the right order.
-    flush ();
-
-    try
-      {
-        out.write (oneByte);
-
-        if (auto_flush && oneByte == '\n')
-          flush ();
-      }
-    catch (IOException e)
-      {
-        setError ();
-      }
+    byte[] data = new byte [1];
+    data [0] = (byte) (oneByte & 0xff);
+    write (data, 0, 1);
   }
 
   /**

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]