79741718

Date: 2025-08-21 00:31:33
Score: 2
Natty:
Report link

You've said in the comments that

I could see some extra bytes added in the corrupted file.

... well there's your problem, rather than "flushing/closing".

What extra bytes? I wonder if it is the "Byte Order Mark". Read about it here https://stackoverflow.com/a/48749396/1847378 - this article is about how to overcome a file/input stream with a BOM that you don't want. That's the opposite problem, though.

Maybe the use of stream is unhelpfully messing around with the stream. Just for a test at least, how about passing ByteArrayOutputStream() to the the outputDocument(..) and then passing byte[] (from ByteArrayOutputStream.toByteArray()) to the JAX RS Response ?

Reasons:
  • Blacklisted phrase (1): this article
  • Blacklisted phrase (1): stackoverflow
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-1):
Posted by: AndrewL