StagingHandler { public void complete() throws IOException { if ( mode == StagingMode.MEMORY ) { final MemoryByteArrayOutputStream stream = (MemoryByteArrayOutputStream) stagingStream.getWrappedStream(); final byte[] bytes = stream.getRaw(); destination.write( bytes, 0, stream.getLength() ); destination.flush(); } else if ( mode == StagingMode.TMPFILE ) { IOUtils.closeQuietly( stagingStream ); stagingStream = null; final BufferedInputStream bis = new BufferedInputStream( new FileInputStream( tmpFile ) ); try { IOUtils.copy( bis, destination ); } finally { IOUtils.closeQuietly( bis ); } } close(); } StagingHandler( final OutputStream outputStream, final StagingMode stagingMode,
      final IPentahoSession userSession ); StagingMode getStagingMode(); boolean isFullyBuffered(); boolean canSendHeaders(); OutputStream getStagingOutputStream(); void complete(); void close(); int getWrittenByteCount();  }
@Test public void testComplete() throws Exception { handler = new StagingHandler( outputStream, StagingMode.MEMORY, session ); handler.complete(); verify( outputStream, times( 1 ) ).write( any( byte[].class ), anyInt(), anyInt() ); verify( outputStream, times( 1 ) ).flush(); }