I'm always confused about how to stream a response back to the client, for example a large csv file, and I'd like to ask some questions:
- I'm reading the file line by line and write directly to the output stream little by little with
flush()
, is this enough or it still depends on theflush()
implementation on the specific OS? - Suppose I have a very powerful machine and only flush at the end, can the client still process the answer in a stream way (without loading all the content into the memory)?
- The client mentioned the response may not be chunked, and it's about Chunked_transfer_encoding, so how does this impact the response? BTW I already know the response size when I send back the file.
- The client also talked about
StreamingResponseBody
. What I understand is this is only for asynchronous processing, we can stream data back without using it. - Last question, does Reactive programming has anything to do with this? My user case is really simple, no concurrent request involved. I know there are a lot of modern frameworks in all the languages, but I'd prefer understand the basic stuff first.
Sorry about all the questions.
flush()
method, I mean when we flush in java, is it guaranteed that the OS will do the flush, because if it's not, then actually it's still possible that data be flushed once to the client. – Desmoid