title: How to stream an endless InputStream with JAX-RS
body: <p>I have an endless <code>InputStream</code> with some data, which I want to return in response to a <code>GET</code> 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:</p>
  
  <pre><code>@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();
              }
          }
      };
  }
  </code></pre>
  
  <p>But content doesn't appear for the client. However, if I add <code>OutputStream#close()</code>, the server delivers the content at that very moment. How can I make it truly streamable?</p>