java - RTFEditorKit read()/write() bug? -


consider following code:

import java.io.bytearrayinputstream; import java.io.bytearrayoutputstream; import java.io.ioexception; import javax.swing.jtextpane; import javax.swing.text.badlocationexception; import javax.swing.text.defaultstyleddocument; import javax.swing.text.styleddocument; import javax.swing.text.rtf.rtfeditorkit;   public class testrtf  {     public static void main(string args[]) throws badlocationexception, ioexception {         new testrtf();     }      public testrtf() throws badlocationexception, ioexception {         styleddocument doc = new defaultstyleddocument();         jtextpane tp = new jtextpane(doc);         doc.insertstring(0, "this test", null);         rtfeditorkit kit = new rtfeditorkit();         for(int i=0; i<4; i++) {             bytearrayoutputstream out = new bytearrayoutputstream();             kit.write(out, doc, 0, doc.getlength());             string s = out.tostring();             system.out.println(s);             system.out.println("-------------------");             doc.remove(0, doc.getlength());             kit.read(new bytearrayinputstream(s.getbytes()), doc, 0);         }             } } 

i expect print out same string 4 times, instead in cycle of reading textpane, , replacing content read results in additional paragraph being created:

{\rtf1\ansi {\fonttbl\f0\fnil monospaced;\f1\fnil dialog;} {\colortbl\red0\green0\blue0;\red51\green51\blue51;}  \f1\fs24\i0\b0\cf1 test\par }  ------------------- {\rtf1\ansi {\fonttbl\f0\fnil monospaced;\f1\fnil dialog;} {\colortbl\red0\green0\blue0;\red51\green51\blue51;}  \li0\ri0\fi0\f1\fs24\i0\b0\ul0\cf1 test\par \li0\ri0\fi0\ul0\par }  ------------------- {\rtf1\ansi {\fonttbl\f0\fnil monospaced;\f1\fnil dialog;} {\colortbl\red0\green0\blue0;\red51\green51\blue51;}  \li0\ri0\fi0\f1\fs24\i0\b0\ul0\cf1 test\par \par \ul0\par }  ------------------- {\rtf1\ansi {\fonttbl\f0\fnil monospaced;\f1\fnil dialog;} {\colortbl\red0\green0\blue0;\red51\green51\blue51;}  \li0\ri0\fi0\f1\fs24\i0\b0\ul0\cf1 test\par \par \par \ul0\par }  ------------------- 

is bug in rtfeditorkit, or doing wrong?

i it's bug in rtfeditorkit.

actually empty defaultstyleddocument (which used in kit internlly) till has 1 paragraph (with 1 \n) in end. looks kit don't care paragraph creates new ones every time rather using existing.

you can try the alternative rtf editor kit supports more things


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -