public function flush_only_invoked_once()
 {
     $output = new StreamingOutput(new MemoryInputStream('Test'));
     $response = new HttpScriptletResponse();
     ob_start();
     $output->writeTo($response, new \peer\URL(), 'application/json');
     $result = ob_get_contents();
     ob_end_clean();
     $this->assertEquals('Test', $result);
 }
 public function of_with_io_element()
 {
     $e = newinstance('io.collections.IOElement', array(new MemoryInputStream('Test')), '{
   protected $stream;
   public function __construct($stream) { $this->stream= $stream; }
   public function getName() { return "test.txt"; }
   public function getURI() { return "/path/to/test.txt"; }
   public function getSize() { return 6100; }
   public function createdAt() { return NULL; }
   public function lastAccessed() { return NULL; }
   public function lastModified() { return new Date("2013-03-26 10:53:00"); }
   public function getOrigin() { return NULL; }
   public function setOrigin(IOCollection $origin) { }
   public function getInputStream() { return $this->stream; }
   public function getOutputStream() { return NULL; }
 }');
     $this->assertEquals(create(new StreamingOutput($e->getInputStream()))->withMediaType('text/plain')->withContentLength(6100)->withLastModified(new \util\Date('2013-03-26 10:53:00')), StreamingOutput::of($e));
 }
 public function download_greeting()
 {
     $s = StreamingOutput::of(new \io\streams\MemoryInputStream('Hello World'))->withMediaType('text/plain; charset=utf-8')->withContentLength(11)->withStatus(200);
     $s->buffered = true;
     // For easier testability!
     return $s;
 }