PrintStream.write(char[]) should only need to flush once when char[] contains several newlines

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Unresolved
    • Priority: P5
    • None
    • Affects Version/s: 7
    • Component/s: core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      In java.io.PrintStream.write(char[] buf): out.flush() is called for every found '\n' char in buf while it should be enough to call it only once (if buf contains '\n').

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Consider the following code:

      System.out.print(new char[] { '\n', '\n'});

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      out.flush() is called twice.
      ACTUAL -
      out.flush() should be called once.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
      if (autoFlush) {
      for (int i = 0; i < buf.length; i++)
      if (buf[i] == '\n')
      out.flush();
      }

      ->

      if (autoFlush) {
      for (int i = 0; i < buf.length; i++)
      if (buf[i] == '\n') {
      out.flush();
      break;
      }
      }

            Assignee:
            Unassigned
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: