I have an infinite InputStream with some data that I want to return in response to an HTTP GET request. I want my web / API client to read it endlessly. How can I do this using JAX-RS? I try 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 the content is not displayed to the client. However, if I add OutputStream#close() , the server is delivering content at this very moment. How can I make it really affordable?
source share