I have been struggling with this weird problem. I pull files from a database saved in binary form (e.g. pdf, images, docs, etc) and stream them to the client's browser using ServletOutputStream. It works like a charm when I
test it in a
Tomcat standalone with
Java Struts from the localhost. No problem. However, files larger than about 60K are truncated when they are streamed back from a remote production server that has the exact same setup as my test environment locally. I tried messing with buffers, flushing, closing, even padding the end of the files. All work well from localhost, but files get truncated (resulting in corrupted files) from the online server. I checked and the files are saved correctly in the database (they have the right length), but when they are streamed, a chunk is chopped off the end. If I use a hex editor to "glue" the chopped bytes back to the end of the corrupted files, they open fine and they are repaired. I suspect some sort of asynchronous action in buffering and sending bytes over the net, but I don't know how to fix it. I would appreciate your help or any good idea! The part of my code where I send the data to the ServletOutputStream is listed below.
Thanks!