title: Java: How do I read from PrintStream?
body: <p>I am trying to read(append incoming data into a local String) from a PrintStram in the following code block:</p>
  
  <pre><code>    System.out.println("Starting Login Test Cases...");
  
      out = new PrintStream(new ByteArrayOutputStream());
              command_feeder = new PipedWriter();
              PipedReader in = new PipedReader(command_feeder);
  
      main_controller = new Controller(in, out);
  
      for(int i = 0; i &lt; cases.length; i++)
      {
                  command_feeder.write(cases[i]);
      }
  </code></pre>
  
  <p>main_controller will be writing some strings to its out(PrintStream), then how can I read from this PrintStream assuming I can't change any code in Controller class? Thanks in advance.</p>