File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Buffer size or other? Please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Buffer size or other? Please help" Watch "Buffer size or other? Please help" New topic

Buffer size or other? Please help

Hongqing Lu

Joined: Jan 14, 2004
Posts: 13
TestServlet runs in Tomcat, it try to get data from socket server then response to client.
It runs well when the data is small. However it will crash when the data is big enough(about 8k). The break point is in the while loop when reading data from BufferedReader in method doSendRequestTCN2.
I have tyied several methods, but all faild.
I have no idea about it.
Is it caused by buffer size or other?
Please help!!!
Sample source code:
public class TestServlet extends HttpServlet {
public void init(ServletConfig servletConfig) throws ServletException {
public void service(HttpServletRequest req,
HttpServletResponse resp) throws ServletException,
IOException {
try {
PrintWriter out = resp.getWriter();
// get response from socket server
String response = Test.doSendRequestTCN2(requestString);
} catch (Exception ex) {
throw new ServletException("Exception in service method: " +
class Test{
public static String doSendRequestTCN2(String input){
StringBuffer fileLines = new StringBuffer();
String response = null;
client = new Socket(host_ip, host_port);

socketWriter = new PrintWriter(client.getOutputStream());
// get stream from socket server
socketReader = new BufferedReader(new InputStreamReader(client.getInputStream()));
String line = null;
int i = 0;
int sizeOfBuffer = 100;
char[] cbuf = new char[sizeOfBuffer];

int chars = 0;
// read from buffered stream
while ( (chars = >= 0) {
fileLines.append(cbuf, 0, chars);
response = fileLines.toString();
catch (Exception e) {
throw new WMSException(e);
return response;
Please help!
Thanks in advance!!!
I agree. Here's the link:
subject: Buffer size or other? Please help
It's not a secret anymore!