tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Konstantin Kolinko" <>
Subject Re: Problem with POST to servlet: 16384 bytes maximum?
Date Sat, 09 Aug 2008 14:28:18 GMT
2008/8/7 Michele Fuortes <>:
> Hi,
> I have a problem with POSTing an XML file to a servlet which writes the XML
> to disk. If the XML file is less than 16384 bytes all goes well. If it's
> bigger the first 16384 bytes are written correctly, the rest all all 00s.
> The lenght of the file is the correct one as in the Content-Length: http
> header.
> The servlet is very simple (I did not write it), the relevant parts are:
>                File file;
>                FileOutputStream out2;
>                DataOutputStream out3;
> ......
>                file = new File(req.getRealPath(filePath));
>                out2 = new FileOutputStream(file);
>                out3 = new DataOutputStream(out2);
> ......
>                bytesAvailable=req.getContentLength();
>                byte[] theBytes=new byte[bytesAvailable];
>      ;
>                out3.write(theBytes,0,bytesAvailable);
>                out3.flush();
> ....
> Can anyone help?

The problem with the above code is that you (or the author of that code,
if you are not the one) do ignore the return value of

That value will be the exact count of bytes that were read into your
buffer in that call of

You have just demonstrated that one cannot read all contentLength
bytes of data in one call.

The easiest fix here will be to use a loop, see Christopher Schultz's
message for an example.

Best regards,
Konstantin Kolinko

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message