title: How to read data from StreamingOutput
body: <p>I have a restful webservice. I am thinking of calling a method from another method in the class. Is it possible? If so, how do I read the content of streaming output in example below? Also, I need both functions separately so that I can return binary files or display text of text files</p>
  
  <pre><code>@Path("/base")
  public class Base{
  
      @GET
      @Path("/base/func1")
      @Produces(MediaType.APPLICATION_OCTET_STREAM)
      public Response func1(){
          final String some_outfilename = "test.pdf";
          StreamingOutput st = new StreamingOutput(){
              @Override
              public void write(OutputStream os) throws IOException{
                  Writer writer = new BufferedWriter(new OutputStreamWriter(os));
                  writer.write("test");
                  writer.flush();
              }
          };
          return Response.ok(stream, MediaType.APPLICATION_OCTET_STREAM).header("content-disposition","attachment; filename =" + some_outFilename).build();
      }
  
      @GET
      @Produces(MediaType.APPLICATION_OCTET_STREAM)
      @Path("/base/func2")
      public Response func2(){
          //I want to call func1() from here, like
          //StreamingOutput st = (StreamingOutput)func1().getEntity();
          //But how do I get the "test" written inside??
          //Once obtained I can return it as response
      }
  }
  </code></pre>
  
  <hr>
  
  <p>EDIT #1:
  func1() does have a return statement. I put it in later (sorry). func2() is also supposed to have a return statement.. I haven't put it because I do not understand how to structure it.</p>