1 package org.apache.maven.shared.release.exec;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.ByteArrayOutputStream;
23 import java.io.FilterOutputStream;
24 import java.io.IOException;
25 import java.io.OutputStream;
26
27
28
29
30 public class TeeOutputStream
31 extends FilterOutputStream
32 {
33 private ByteArrayOutputStream bout = new ByteArrayOutputStream( 1024 * 8 );
34 private byte indent[];
35 private int last = '\n';
36
37 public TeeOutputStream( OutputStream out )
38 {
39 this( out, " " );
40 }
41
42 public TeeOutputStream( OutputStream out, String i )
43 {
44 super( out );
45 indent = i.getBytes();
46 }
47
48 public void write( byte[] b, int off, int len )
49 throws IOException
50 {
51 for ( int x = 0; x < len; x++ )
52 {
53 int c = b[off + x];
54 if ( last == '\n' || ( last == '\r' && c != '\n' ) )
55 {
56 out.write( b, off, x );
57 bout.write( b, off, x );
58 out.write( indent );
59 off += x;
60 len -= x;
61 x = 0;
62 }
63 last = c;
64 }
65 out.write( b, off, len );
66 bout.write( b, off, len );
67 }
68
69 public void write( int b )
70 throws IOException
71 {
72 if ( last == '\n' || ( last == '\r' && b != '\n' ) )
73 {
74 out.write( indent );
75 }
76 out.write( b );
77 bout.write( b );
78 last = b;
79 }
80
81 public String toString()
82 {
83 return bout.toString();
84 }
85
86 public String getContent()
87 {
88 return bout.toString();
89 }
90
91 }