I have an endless InputStream
with some data, which I want to return in response to a GET
HTTP request. I want my web/API client to read from it endlessly. How can I do it with JAX-RS? I'm trying this:
@GET
@Path("/stream")
@Produces(MediaType.TEXT_PLAIN)
public StreamingOutput stream() {
final InputStream input = // get it
return new StreamingOutput() {
@Override
public void write(OutputStream out) throws IOException {
while (true) {
out.write(input.read());
out.flush();
}
}
};
}
But content doesn't appear for the client. However, if I add OutputStream#close()
, the server delivers the content at that very moment. How can I make it truly streamable?