Hello,
Here is a Servlet that produces text from the Jungle Book,
with increasing text length.
It seems that the problem only manifests itself if the
number of elements is large. I should have said in my first
posting that the output was a few pages, not a few lines.
Best regards,
-- David Tonhofer
--On Monday, September 02, 2002 8:27 PM +0200 "David Tonhofer, m-plify
S.A." <[EMAIL PROTECTED]> wrote:
> Ok, thanks. I will try to reproduce ASAP...will try to find
> an hour tomorrow. But I'm currently positively *wrestling*
> with some other code issues 8-( ... (aren't we all?)
>
> --On Monday, September 02, 2002 11:30 AM -0500 Stephan Nagy
> <[EMAIL PROTECTED]> wrote:
>
>> I cannot reproduce this problem, here is my test case.
[snip]
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
import org.apache.ecs.html.TT;
import org.apache.ecs.html.Input;
import org.apache.ecs.html.H3;
import org.apache.ecs.Document;
import org.apache.ecs.Entities;
import org.apache.ecs.html.BR;
import org.apache.ecs.Doctype;
import org.apache.ecs.html.Form;
public class ECSTestCase extends javax.servlet.http.HttpServlet {
public void doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws
javax.servlet.ServletException, java.io.IOException {
performTask(request, response);
}
public void doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws
javax.servlet.ServletException, java.io.IOException {
performTask(request, response);
}
private void performTask(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws
javax.servlet.ServletException, java.io.IOException {
final String DATA =
"It was seven o'clock of a very warm evening in the Seeonee hills\n"
+ "when Father Wolf woke up from his day's rest, scratched himself,\n"
+ "yawned, and spread out his paws one after the other to get rid of\n"
+ "the sleepy feeling in their tips. Mother Wolf lay with her big\n"
+ "gray nose dropped across her four tumbling, squealing cubs, and\n"
+ "the moon shone into the mouth of the cave where they all lived.\n"
+ "\"Augrh!\" said Father Wolf. \"It is time to hunt again.\" He
was\n"
+ "going to spring down hill when a little shadow with a bushy tail\n"
+ "crossed the threshold and whined: \"Good luck go with you, O
Chief\n"
+ "of the Wolves. And good luck and strong white teeth go with
noble\n"
+ "children that they may never forget the hungry in this world.\"\n"
+ "\n"
+ "It was the jackal--Tabaqui, the Dish-licker--and the\n"
+ "wolves of India despise Tabaqui because he runs about making\n"
+ "mischief, and telling tales, and eating rags and pieces of
leather\n"
+ "from the village rubbish-heaps. But they are afraid of him too,\n"
+ "because Tabaqui, more than anyone else in the jungle, is apt to
go\n"
+ "mad, and then he forgets that he was ever afraid of anyone, and\n"
+ "runs through the forest biting everything in his way. Even the\n"
+ "tiger runs and hides when little Tabaqui goes mad, for madness is\n"
+ "the most disgraceful thing that can overtake a wild creature. We\n"
+ "call it hydrophobia, but they call it dewanee--the madness--\n"
+ "and run.\n"
+ "\n"
+ "\"Enter, then, and look,\" said Father Wolf stiffly, \"but there\n"
+ "is no food here.\"\n"
+ "\n"
+ "\"For a wolf, no,\" said Tabaqui, \"but for so mean a person as\n"
+ "myself a dry bone is a good feast. Who are we, the Gidur-log
[the\n"
+ "jackal people], to pick and choose?\" He scuttled to the back of\n"
+ "the cave, where he found the bone of a buck with some meat on it,\n"
+ "and sat cracking the end merrily.\n"
+ "\n"
+ "\"All thanks for this good meal,\" he said, licking his lips.\n"
+ "\"How beautiful are the noble children! How large are their
eyes!\n"
+ "And so young too! Indeed, indeed, I might have remembered that\n"
+ "the children of kings are men from the beginning.\"\n"
+ "\n"
+ "Now, Tabaqui knew as well as anyone else that there is nothing\n"
+ "so unlucky as to compliment children to their faces. It pleased\n"
+ "him to see Mother and Father Wolf look uncomfortable.\n"
+ "\n"
+ "Tabaqui sat still, rejoicing in the mischief that he had made,\n"
+ "and then he said spitefully:\n"
+ "\n"
+ "\"Shere Khan, the Big One, has shifted his hunting grounds. He\n"
+ "will hunt among these hills for the next moon, so he has told
me.\"\n"
+ "\n"
+ "Shere Khan was the tiger who lived near the Waingunga River,\n"
+ "twenty miles away.\n"
+ "\n"
+ "\"He has no right!\" Father Wolf began angrily--\"By the Law\n"
+ "of the Jungle he has no right to change his quarters without due\n"
+ "warning. He will frighten every head of game within ten miles,\n"
+ "and I--I have to kill for two, these days.\"\n"
+ "\n"
+ "\"His mother did not call him Lungri [the Lame One] for\n"
+ "nothing,\" said Mother Wolf quietly. \"He has been lame in one
foot\n"
+ "from his birth. That is why he has only killed cattle. Now the\n"
+ "villagers of the Waingunga are angry with him, and he has come\n"
+ "here to make our villagers angry. They will scour the jungle for\n"
+ "him when he is far away, and we and our children must run when
the\n"
+ "grass is set alight. Indeed, we are very grateful to Shere
Khan!\"\n"
+ "\n"
+ "\"Shall I tell him of your gratitude?\" said Tabaqui.\n"
+ "\n"
+ "\"Out!\" snapped Father Wolf. \"Out and hunt with thy master.\n"
+ "Thou hast done harm enough for one night.\"\n"
+ "\n"
+ "\"I go,\" said Tabaqui quietly. \"Ye can hear Shere Khan below\n"
+ "in the thickets. I might have saved myself the message.\"\n"
+ "\n"
+ "Father Wolf listened, and below in the valley that ran down to\n"
+ "a little river he heard the dry, angry, snarly, singsong whine of\n"
+ "a tiger who has caught nothing and does not care if all the
jungle\n"
+ "knows it.\n"
+ "\n"
+ "\"The fool!\" said Father Wolf. \"To begin a night's work with\n"
+ "that noise! Does he think that our buck are like his fat\n"
+ "Waingunga bullocks?\"\n"
+ "\n"
+ "\"H'sh. It is neither bullock nor buck he hunts to-night,\"\n"
+ "said Mother Wolf. \"It is Man.\"\n"
+ "\n"
+ "The whine had changed to a sort of humming purr that seemed to\n"
+ "come from every quarter of the compass. It was the noise that\n"
+ "bewilders woodcutters and gypsies sleeping in the open, and makes\n"
+ "them run sometimes into the very mouth of the tiger.\n"
+ "\n"
+ "\"Man!\" said Father Wolf, showing all his white teeth. \"Faugh!\n"
+ "Are there not enough beetles and frogs in the tanks that he must\n"
+ "eat Man, and on our ground too!\"\n"
+ "\n"
+ "The Law of the Jungle, which never orders anything without a\n"
+ "reason, forbids every beast to eat Man except when he is killing\n"
+ "to show his children how to kill, and then he must hunt outside\n"
+ "the hunting grounds of his pack or tribe. The real reason for\n"
+ "this is that man-killing means, sooner or later, the arrival of\n"
+ "white men on elephants, with guns, and hundreds of brown men with\n"
+ "gongs and rockets and torches. Then everybody in the jungle\n"
+ "suffers. The reason the beasts give among themselves is that Man\n"
+ "is the weakest and most defenseless of all living things, and it\n"
+ "is unsportsmanlike to touch him. They say too--and it is true\n"
+ "--that man-eaters become mangy, and lose their teeth.\n"
+ "\n"
+ "The purr grew louder, and ended in the full-throated \"Aaarh!\"\n"
+ "of the tiger's charge.\n"
+ "\n"
+ "Then there was a howl--an untigerish howl--from Shere\n"
+ "Khan. \"He has missed,\" said Mother Wolf. \"What is it?\"\n"
+ "\n"
+ "Father Wolf ran out a few paces and heard Shere Khan muttering\n"
+ "and mumbling savagely as he tumbled about in the scrub.\n"
+ "\n"
+ "\"The fool has had no more sense than to jump at a woodcutter's\n"
+ "campfire, and has burned his feet,\" said Father Wolf with a
grunt.\n"
+ "\"Tabaqui is with him.\"\n"
+ "\n"
+ "\"Something is coming uphill,\" said Mother Wolf, twitching one\n"
+ "ear. \"Get ready.\"\n";
//
// the servlet request contains 'limit', the max. number of characters to
output as TT
// this value is now extracted (if it exists) and the next limit up the scale
is computed
//
int limit = 0;
{
String limitStr = request.getParameter("limit");
if (limitStr != null) {
try {
limit = Integer.parseInt(limitStr);
} catch (NumberFormatException exe) {
}
}
if (request.getParameter("restart") != null) {
limit = 0;
}
}
int MORE_CHARACTERS = 500;
int nextLimit = limit + MORE_CHARACTERS;
//
// set up the document, the 'tt' element is set up later
//
Document doc;
TT tt;
{
doc = new Document();
doc.setDoctype(new Doctype.Html40Transitional());
doc.appendBody(new H3("Limit is now " + limit));
tt = new TT();
doc.appendBody(tt);
Form form = new Form();
doc.appendBody(form);
form.setAction(request.getServletPath());
form.setMethod(form.POST);
form.setName("junglebook");
form.addElement(new Input(Input.HIDDEN, "limit", nextLimit));
form.addElement(new Input(Input.SUBMIT, "encore", "Encore une fois!"));
form.addElement(new Input(Input.SUBMIT, "restart", "Restart"));
doc.appendBody(tt);
}
//
// HERE COMES THE BEEF.
// The 'TT' element is created; note that one of two loops can be chosen;
// The original (David's) and Stephan's. Stephan's has been modified to
// actually read from 'buffer' not (erroneously) from 'DATA'.
// Here we go:
//
java.io.StringReader reader = new java.io.StringReader(DATA.substring(0,
limit));
final int BUFFERSIZE = 256;
final boolean USE_DAVIDS_LOOP = !true;
char[] buffer = new char[BUFFERSIZE];
try {
if (USE_DAVIDS_LOOP) {
int actuallyRead;
do {
actuallyRead = reader.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);
} else {
while (true) {
int read = reader.read(buffer);
if (read == -1) {
break;
}
for (int x = 0; x < read; x++) {
if (buffer[x] == '\n') {
tt.addElement(new BR());
} else if (buffer[x] == ' ') {
tt.addElement(Entities.NBSP);
} else {
tt.addElement(new String(buffer, x, 1));
}
}
}
}
doc.output(response.getWriter());
} catch (java.io.IOException ioe) {
ioe.printStackTrace();
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>