1
2
3
4
5
6
7
8
9
10
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 }