Don't use ObjectOutputStream
. It's for writing serialized Java objects, not for writing raw binary data. It may indeed block the stream. Rather just write directly to the OutputStream
of the URL connection.
That said, the code looks pretty overcomplicated. Even after re-reading several times and blinking my eyes countless times, I can't get it right. I suggest you to send those files according the multipart/form-data
encoding with help of Commons HttpClient. You can find here a basic code example. You just have to modify Part[] parts
to include all the files. The servlet on the other side can in turn use Commons FileUpload to parse the multipart/form-data
request.
To calculate the progress, I'd suggest to pick CountingOutputStream
of Commons IO. Just wrap the OutputStream
with it and write to it.
Update: if you don't like to ship your applet with more 3rd party libraries (which I imagine is reasonable), then have a look at this code snippet (and the original question mentioned as 1st link) how to create a multipart/form-data
body yourself using URLConnection
.