Not having received any answer so far, I dare to repost....

Hello,

Just a question regarding weird behaviour of an ECS code
snippet. I was wondering whether this is *supposed to happen*
because I haven't understood how to use ECS properly or
something. Here goes:

1) I get text from an InputStream and want to write it to
   HTML output as <tt>foo</tt> inside a servlet.

2) I thought this might do it (ok, so I *DO* have a more
   efficient loop, this for illustration purposes..copy
   character by character, replace newlines or carriage
   returns by <BR>, replaces space by &nbsp;):

        Document doc = new Document();
        doc.setDoctype(new Doctype.Html40Transitional());
        TT tt = new TT();
        char[] buffer = new char[BUFFERSIZE];
        int actuallyRead;
        do {
                actuallyRead = isr.read(buffer);
                int startOff = 0;
                for (int i = 0; i < actuallyRead; i++) {
                        if (buffer[i] == '\n' || buffer[i] == '\r') {
                                tt.addElement(new BR());
                        } else if (buffer[i] == ' ') {
                                tt.addElement(Entities.NBSP);
                        } else {
                                tt.addElement(new String(buffer,i,1));
                        }
                }
        } while (actuallyRead == buffer.length);
        doc.appendBody(tt);
        doc.output(res.getWriter());

3) When I run that though, the output is horribly mangled
   as if the structure underlying TT was messing things up
   (something to do with the Hashtable implementation?)
   A sample output:

   C noToller3inforeat ona-  - - --- ----------------------------
   Total irount of memory in VM  - :v89791 KByte
   Amoent  f  emory stile available: 9897 KBy e
   Amount  f0 emo  eused      -     p79894 KByte C n truct time

   This changes between 'updates'...

4) For comparison, just piping the text to the ouput page
   (after having given it content type text/plain) gives:

   Controller information
   ---------------------------------------
   Total amount of memory in VM    : 89791 KByte
   Amount of memory still available: 6818 KByte
   Amount of memory used           : 82973 KByte
   Construct time                  : 2002.08.28 10:36:52:188 (@1030523812188


So...am I sadly mistaken or is something going on?

Best regards,

        -- David Tonhofer
        m-plify S.A.


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to