Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4124162

swing.text.DefaultEditorKit.write(OutputStream,..) should invoke flush

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      swing1.1
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



      Name: akC57697 Date: 03/31/98



      The java.awt.swing.text.DefaultEditorKit.write(OutputStream,..) does not
      work properly. It should invoke flush() to write buffered data to the
      given OutputStream.
        The reason of the problem is next: DefaultEditorKit.write(OutputStream,..)
      invokes DefaultEditorKit.write(Writer,..) using new OutputStreamWriter(out)
      and does not flush internal buffer of this OutputStreamWriter.

      You may see data lossage in the example.

      -----------------------Example--------------------
      import java.awt.swing.text.*;
      import java.io.*;
      public class testDefaultKit {
          public static void main(String s[]) {
          
            String string = new String("A string");
            java.io.StringReader reader = new java.io.StringReader(string);
            DefaultEditorKit editor = new DefaultEditorKit();
            Document doc = new PlainDocument();
            PrintWriter writer = new PrintWriter(System.out);
            
            try {
             editor.read(reader,doc,0); // Insert the string
             reader.close();
                                                    
             System.out.print("Writer: ");
             editor.write(writer,doc,0,doc.getLength()); // Use a Writer
             writer.flush();
             
             System.out.println();
             
             System.out.print("OutputStream: ");
             editor.write(System.out,doc,0,doc.getLength()); // Use a OutputStream
             System.out.flush();

             System.out.println();
                                                                 
            } catch (Exception e) {
                     System.out.println("Unexpected : "+e);
                     return;
                    }
        }
      }
      --------------------------------------------------
      Output:
      Writer: A string
      OutputStream:

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            tprinzinsunw Timothy Prinzing (Inactive)
            Reporter:
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: