MemStagingHandler extends AbstractStagingHandler { @Override public void complete() throws IOException { final MemoryByteArrayOutputStream stream = (MemoryByteArrayOutputStream) memoryTrackingStream.getWrappedStream(); final ByteArrayInputStream inputStream = new ByteArrayInputStream( stream.getRaw() ); IOUtils.copy( inputStream, outputStream ); } MemStagingHandler( final OutputStream outputStream, final IPentahoSession userSession ); @Override void complete(); @Override void close(); @Override int getWrittenByteCount(); @Override boolean canSendHeaders(); @Override OutputStream getStagingOutputStream(); @Override boolean isFullyBuffered(); @Override StagingMode getStagingMode();  }
@Test public void completeTest() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); MemStagingHandler handler = new MemStagingHandler( baos, session ); handler.getStagingOutputStream().write( TEST.getBytes() ); assertTrue( "complete was not called", new String( baos.toByteArray() ).isEmpty() ); handler.complete(); assertEquals( "Write output only after complete", TEST, baos.toString().trim() ); }