Harry Anan wrote:... but it looks like infinite loop no errors in servlet even after 20 mins. This is the snippet from my servlet -please let me know if I miss something.
Also is this going to take lot of CPU time because of reading 100+MB in 4KB chunks?
It "looks like" infinite loop? You haven't put debugging statements in there to see what's really going on? Better still
you should be debugging this code in a standalone
Java class, rather than using a servlet container as your
test base.
And yes, it's going to take a lot of CPU time to read 100 MB of data. And more to the point, it's going to take a lot of elapsed time in your case because the data is coming slowly over the network. You should expect your code which processes the upload to run faster than the data arrives, so don't waste your time worrying about CPU time.
As for the code, I don't understand why you create a new ByteArrayOutputStream for each chunk of data you read. You could be creating a new ByteArrayOutputStream for each byte in the worst case. That code should be outside the loop which fills the buffer. And you're always writing 4096 bytes from the buffer even if you didn't read 4096 bytes from the buffer. This will give you extra junk at the end of the file in most cases. (In your code you break out of the loop, so you throw away the last buffer, but that should be fixed if you put the writing outside the loop.)