1

So I have a servlet, where in response I am writing big chunk of data.

In order to avoid loading entire chunk of data in memory, I read the data in chunk, and "flush" out the stream. (Even if I won't do, servletresponse will flush the buffer if buffer limit is reached).

Now after flushing chunks of data, I ended up getting an error in processing next chunk of data.

How to send error indication to client, as the status has already been sent to client and one set of data has already been set.

After commit, we can't change the status of response, add new headers as per spec.

Any suggestion?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Optional
  • 4,387
  • 4
  • 27
  • 45

1 Answers1

3

There's no way.

Your best alternative is to write to a temporary file instead of the response body. When a processing error occurs during this step, then you can send the error response the way you want. Else you can safely stream from the temporary file to the response body.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555