tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Funk <funk...@joedog.org>
Subject Re: Problem with binary HTTP 1.0 POST
Date Thu, 19 Jun 2003 11:01:36 GMT
read() may also return 0 or -1. -1 for end of file. Also the implementation 
of read is done that subsequent reads also return -1. Also make sure your 
posting byte calculation is correct.

Problem code:
 >         int bytesRead = inStream.read(inData);
 >         fileOutStream.write(inData, 0, bytesRead);
 >         totalBytesRead += bytesRead;

Alternative:
...
int contentLength = request.getContentLength();

InputStream inStream = request.getInputStream();
FileOutputStream fileOutStream = new FileOutputStream("SomePhoto.jpg");

byte[] inData = new byte[100];
int totalBytesRead = 0;
int bytesRead = inStream.read(inData);

while(bytesRead>=0 && totalBytesRead<contentLength) {
     fileOutStream.write(inData, 0, bytesRead);
     totalBytesRead += bytesRead;
     bytesRead = inStream.read(inData);
}

if (totalBytesRead<contentLength) {
     log("I didn't get enough data!");
}

inStream.close();
fileOutStream.close();

...



History detail of original message can be found at:
http://marc.theaimsgroup.com/?l=tomcat-user&m=105600834631106&w=2



-Tim


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message