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

RTFEditorKit.write(OututStream,...) throws unexpected InternalError.

    XMLWordPrintable

Details

    • swing1.0.2
    • x86, sparc
    • solaris_2.5.1, windows_nt
    • Verified

    Description



      Name: aaC67449 Date: 04/17/98



        RTFEditorKit.write(OututStream,...) throws unexpected InternalError, when it must work correctly.

      Javadoc says:"
      public void write(OutputStream out,
                        Document doc,
                        int pos,
                        int len) throws IOException, BadLocationException

          Write content from a document to the given stream in a format
          appropriate for this kind of content handler.
          Parameters:
              out - The stream to write to
              doc - The source for the write.
              pos - The location in the document to fetch the content.
              len - The amount to write out.
          Throws:
              IOException - on any I/O error
              BadLocationException - if pos represents an invalid location
              within the document.
      "
        So InternalError is not right exception any time.
        
      ------------------Example-----------------------------------
      import java.awt.swing.text.rtf.*;
      import java.awt.swing.text.*;
      import java.io.*;
      public class Test {

         public static void main(String argv[]) {
          String test="{\\rtf1\\ansi\\deff0\\deftab720{\\fonttbl{\\f0\\fswiss MS Sans Serif;}}{\\colortbl\\red0\\green0\\blue0;}\\plain\\f0 Test}";
             RTFEditorKit c= new RTFEditorKit();
              Document doc=c.createDefaultDocument();
              try {
                  c.read(new ByteArrayInputStream(test.getBytes("8859_1")),doc,0);
                  ByteArrayOutputStream sw=new ByteArrayOutputStream();
                  
                  c.write(sw,doc,0,4); // write full text , no Exception expected
                  System.out.println(sw.toString("8859_1"));
              } catch(Exception e) {
                  e.printStackTrace();
              }
        
         }

      }

      -------------------Output------------------------------------
      reading charset ansi
      Unknown keyword: deff (param 0)
      Unknown keyword: deftab (param 720)
      Done reading font table.
      Number 0: MS Sans Serif
       
      Done reading color table, 1 entries.
      RTF filter done.
      java.lang.InternalError: Invalid location
              at java.awt.swing.text.rtf.RTFGenerator.writeTextElement(RTFGenerator.java:800)
              at java.awt.swing.text.rtf.RTFGenerator.writeParagraphElement(RTFGenerator.java:658)
              at java.awt.swing.text.rtf.RTFGenerator.writeDocument(RTFGenerator.java:132)
              at java.awt.swing.text.rtf.RTFEditorKit.write(RTFEditorKit.java:108)
              at Test.main(Test.java:14)
       

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

      Attachments

        Issue Links

          Activity

            People

              tprinzing Tim Prinzing
              aalievsunw Artem Aliev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: