File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes Size problem in http message? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Size problem in http message?" Watch "Size problem in http message?" New topic

Size problem in http message?

Roberto Calanca

Joined: Feb 27, 2003
Posts: 2
I'm writing a client-server application to upload a file to a server using servlet.
Client side I read a a file and sentit on the output stream obtained with connection.getOutputStream() ;. When I try to send small files (<20k) all works wery well, but if I try to transfer a bigger file (about 500k or more), at the following instruction:
BufferedReader inPage = new BufferedReader(new InputStreamReader(connection.getInputStream()));
I'have the following IOException: Error writing to server
at ( (pc 546)
at ( (pc 603)
at ( (pc 130)
at MyClient.main
Do someone have any idea?
Thank you for your attention
Roberto Calanca
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Roberto,
The problem is probably with the default buffer size of BufferedReader. From the javadocs for BufferedReader:
The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.
So you could try setting the buffer to a higher value with:

You would probably be better off breaking the huge file into smaller chunks and/or wrapping the clients output in a DeflaterOutputStream.
Hope this helps,
Michael Morris

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Roberto Calanca

Joined: Feb 27, 2003
Posts: 2
Thank you Morris,
I found a more radical solution installing a JRE 1.3.1 more recent version. Infact this problem seamed strange to me because running the same client.class on windows and JRE 1.4.0 it works very well, instead I had the problem running on HP OpenVMS JRE 1.3.1-1.
I've never thought to a buffer size problem because the exception appears opening the connection.getInputStreaReader (when is sent the POST request) and not writing data to then connection.getOutputStream Stream.
Thank you once more.
Roberto Calanca
sandeep darvekar

Joined: Sep 22, 2006
Posts: 1
could you please tell how to arrive at buffer size? Say I have to upload a file of 5MB using a multipart request, how much should be the buffer size?
FYI, I am using apache-commons-fileupload for the same.


Thanks<br />Sandeep Darvekar
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Sandeep, welcome to JavaRanch. You're replying to a thread that's more than 3 years old, making it unlikely that the original participants are still following it.

Setting the buffer size is a matter of trial and error. Have you set it large enough that it can hold the entire file - does that work? If so, you can then try to make it smaller by halves if you're concerned about memory consumption.
I agree. Here's the link:
subject: Size problem in http message?
jQuery in Action, 3rd edition