I'm writing a custom tag that reads data from a servlet, and writes it back
out to the page. Currently, I read data from the servlet into a large char
array buffer and append only the characters read to a StringBuffer. Then,
when everything's read from the servlet, I write the String representation
of the StringBuffer to the JspWriter. (The current code is below.)
For efficiency, though, what I'd like to do is bypass the StringBuffer
completely and just print the characters read directly to the
JspWriter. Can this be done i.e. something like
"pageContext.getOut().print(buffer, 0, charsRead);"?
StringBuffer data = new StringBuffer();
char [] buffer = new char[BUFFER_SIZE];
inReader = new InputStreamReader(new BufferedInputStream(inStream));
int charsRead = 0;
while (true) {
charsRead = inReader.read(buffer, 0, BUFFER_SIZE);
if (charsRead < 1) {
break;
}
data.append(buffer, 0, charsRead);
}
pageContext.getOut().print(data.toString());
pageContext.getOut().flush();
(To save other discussions, please don't suggest things like <jsp:include>,
as the functionality described is how the tag needs to work.)
Thanks.
Jay
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com