View Javadoc

1   /*
2    *  soapUI, copyright (C) 2004-2010 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;
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  	@Override
30  	public int read() throws IOException
31  	{
32  		int i = super.read();
33  		capture.write( i );
34  		return i;
35  	}
36  
37  	@Override
38  	public int read( byte[] b ) throws IOException
39  	{
40  		int i = super.read( b );
41  		capture.write( b );
42  		return i;
43  	}
44  
45  	@Override
46  	public int read( byte[] b, int off, int len ) throws IOException
47  	{
48  		int i = super.read( b, off, len );
49  		if( i > 0 )
50  			capture.write( b, off, i );
51  		return i;
52  	}
53  
54  	public byte[] getCapturedData()
55  	{
56  		return capture.toByteArray();
57  	}
58  }