View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2008 eviware.com 
3    *
4    *  soapUI is free software; you can redistribute it and/or modify it under the 
5    *  terms of version 2.1 of the GNU Lesser General Public License as published by 
6    *  the Free Software Foundation.
7    *
8    *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
9    *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
10   *  See the GNU Lesser General Public License for more details at gnu.org.
11   */
12  
13  package com.eviware.soapui.impl.wsdl.monitor.jettyproxy;
14  
15  import java.io.ByteArrayOutputStream;
16  import java.io.FilterInputStream;
17  import java.io.IOException;
18  import java.io.InputStream;
19  
20  public class CaptureInputStream extends FilterInputStream
21  {
22  	private final ByteArrayOutputStream capture = new ByteArrayOutputStream();
23  
24  	public CaptureInputStream( InputStream in )
25  	{
26  		super( in );
27  	}
28  
29  	public int read() throws IOException
30  	{
31  		int i = super.read();
32  		capture.write( i );
33  		return i;
34  	}
35  
36  	public int read( byte[] b ) throws IOException
37  	{
38  		int i = super.read( b );
39  //		capture.write( b );
40  		return i;
41  	}
42  	
43  	public int read( byte[] b, int off, int len ) throws IOException
44  	{
45  		int i = super.read( b, off, len );
46  		if( i > 0 ) {
47  			capture.write( b, off, i );
48  		}
49  		return i;
50  	}
51  
52  	public byte[] getCapturedData()
53  	{
54  		return capture.toByteArray();
55  	}
56  }