aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Size problem in http message?" Watch "Size problem in http message?" New topic
Author

Size problem in http message?

Roberto Calanca
Greenhorn

Joined: Feb 27, 2003
Posts: 2
Hi,
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:
java.io.IOException: Error writing to server
at sun.net.www.protocol.http.HttpURLConnection.writeRequests (HttpURLConnection.java:250) (pc 546)
at sun.net.www.protocol.http.HttpURLConnection.writeRequests (HttpURLConnection.java:258) (pc 603)
at sun.net.www.protocol.http.HttpURLConnection.getInutStream (HttpURLConnection.java:509) (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
Greenhorn

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
Greenhorn

Joined: Sep 22, 2006
Posts: 1
Hello,
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
Sandeep


Thanks<br />Sandeep Darvekar
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42285
    
  64
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.


Ping & DNS - my free Android networking tools app
 
Consider Paul's rocket mass heater.
 
subject: Size problem in http message?