You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by pg...@apache.org on 2002/10/23 20:31:07 UTC

cvs commit: jakarta-james/src/java/org/apache/james/util InternetPrintWriter.java

pgoldstein    2002/10/23 11:31:07

  Modified:    src/java/org/apache/james/util InternetPrintWriter.java
  Log:
  Fixed an auto flush bug in InternetPrintWriter.
  Prior to this change, the InternetPrintWriter always
  flushed, whether the auto flush was set to true or
  false.  It also didn't keep the lock on the stream
  between the print and the flush, contrary to contract.
  
  Revision  Changes    Path
  1.3       +88 -77    jakarta-james/src/java/org/apache/james/util/InternetPrintWriter.java
  
  Index: InternetPrintWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/util/InternetPrintWriter.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InternetPrintWriter.java	16 Aug 2002 21:06:32 -0000	1.2
  +++ InternetPrintWriter.java	23 Oct 2002 18:31:07 -0000	1.3
  @@ -18,64 +18,75 @@
   public class InternetPrintWriter
       extends PrintWriter {
   
  -/**
  - * The line separator to use.
  - */
  +    /**
  +     * The line separator to use.
  +     */
       private static String lineSeparator = "\r\n";
   
  -/**
  - * Constructor that takes a writer to wrap.
  - *
  - * @param out the wrapped Writer
  - */
  +    /**
  +     * Whether the Writer autoflushes on line feeds
  +     */
  +    private final boolean autoFlush;
  +
  +    /**
  +     * Constructor that takes a writer to wrap.
  +     *
  +     * @param out the wrapped Writer
  +     */
       public InternetPrintWriter (Writer out) {
           super (out);
  +        autoFlush = false;
       }
   
  -// TODO: This class handles autoflush incorrectly
  -
  -/**
  - * Constructor that takes a writer to wrap.
  - *
  - * @param out the wrapped Writer
  - * @param autoFlush whether to flush after each print call
  - */
  +    /**
  +     * Constructor that takes a writer to wrap.
  +     *
  +     * @param out the wrapped Writer
  +     * @param autoFlush whether to flush after each print call
  +     */
       public InternetPrintWriter (Writer out, boolean autoFlush) {
           super (out, autoFlush);
  +        this.autoFlush = autoFlush;
       }
   
  -/**
  - * Constructor that takes a stream to wrap.
  - *
  - * @param out the wrapped OutputStream
  - */
  +    /**
  +     * Constructor that takes a stream to wrap.
  +     *
  +     * @param out the wrapped OutputStream
  +     */
       public InternetPrintWriter (OutputStream out) {
           super (out);
  +        autoFlush = false;
       }
   
  -/**
  - * Constructor that takes a stream to wrap.
  - *
  - * @param out the wrapped OutputStream
  - * @param autoFlush whether to flush after each print call
  - */
  +    /**
  +     * Constructor that takes a stream to wrap.
  +     *
  +     * @param out the wrapped OutputStream
  +     * @param autoFlush whether to flush after each print call
  +     */
       public InternetPrintWriter (OutputStream out, boolean autoFlush) {
           super (out, autoFlush);
  +        this.autoFlush = autoFlush;
       }
   
  -/**
  - * Print a line separator.
  - */
  +    /**
  +     * Print a line separator.
  +     */
       public void println () {
  -        print (lineSeparator);
  -        super.flush();
  +        synchronized (lock) {
  +            write(lineSeparator);
  +            if (autoFlush) {
  +                flush();
  +            }
  +        }
       }
   
  -/**
  - * Print a boolean followed by a line separator.
  - *
  - * @param x the boolean to print
  - */
  +    /**
  +     * Print a boolean followed by a line separator.
  +     *
  +     * @param x the boolean to print
  +     */
       public void println(boolean x) {
           synchronized (lock) {
               print(x);
  @@ -83,11 +94,11 @@
           }
       }
   
  -/**
  - * Print a char followed by a line separator.
  - *
  - * @param x the char to print
  - */
  +    /**
  +     * Print a char followed by a line separator.
  +     *
  +     * @param x the char to print
  +     */
       public void println(char x) {
           synchronized (lock) {
               print (x);
  @@ -95,11 +106,11 @@
           }
       }
   
  -/**
  - * Print a int followed by a line separator.
  - *
  - * @param x the int to print
  - */
  +    /**
  +     * Print a int followed by a line separator.
  +     *
  +     * @param x the int to print
  +     */
       public void println (int x) {
           synchronized (lock) {
               print (x);
  @@ -107,11 +118,11 @@
           }
       }
   
  -/**
  - * Print a long followed by a line separator.
  - *
  - * @param x the long to print
  - */
  +    /**
  +     * Print a long followed by a line separator.
  +     *
  +     * @param x the long to print
  +     */
       public void println (long x) {
           synchronized (lock) {
               print (x);
  @@ -119,11 +130,11 @@
           }
       }
   
  -/**
  - * Print a float followed by a line separator.
  - *
  - * @param x the float to print
  - */
  +    /**
  +     * Print a float followed by a line separator.
  +     *
  +     * @param x the float to print
  +     */
       public void println (float x) {
           synchronized (lock) {
               print (x);
  @@ -131,11 +142,11 @@
           }
       }
   
  -/**
  - * Print a double followed by a line separator.
  - *
  - * @param x the double to print
  - */
  +    /**
  +     * Print a double followed by a line separator.
  +     *
  +     * @param x the double to print
  +     */
       public void println (double x) {
           synchronized (lock) {
               print (x);
  @@ -143,11 +154,11 @@
           }
       }
   
  -/**
  - * Print a character array followed by a line separator.
  - *
  - * @param x the character array to print
  - */
  +    /**
  +     * Print a character array followed by a line separator.
  +     *
  +     * @param x the character array to print
  +     */
       public void println (char[] x) {
           synchronized (lock) {
               print (x);
  @@ -155,11 +166,11 @@
           }
       }
   
  -/**
  - * Print a String followed by a line separator.
  - *
  - * @param x the String to print
  - */
  +    /**
  +     * Print a String followed by a line separator.
  +     *
  +     * @param x the String to print
  +     */
       public void println (String x) {
           synchronized (lock) {
               print (x);
  @@ -167,11 +178,11 @@
           }
       }
   
  -/**
  - * Print an Object followed by a line separator.
  - *
  - * @param x the Object to print
  - */
  +    /**
  +     * Print an Object followed by a line separator.
  +     *
  +     * @param x the Object to print
  +     */
       public void println (Object x) {
           synchronized (lock) {
               print (x);
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>