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 public class TeeOutputStream
28 extends FilterOutputStream
29 {
30 private ByteArrayOutputStream bout = new ByteArrayOutputStream( 1024 * 8 );
31 private byte indent[];
32 private int last = '\n';
33
34 public TeeOutputStream( OutputStream out )
35 {
36 this( out, " " );
37 }
38
39 public TeeOutputStream( OutputStream out, String i )
40 {
41 super( out );
42 indent = i.getBytes();
43 }
44
45 public void write( byte[] b, int off, int len )
46 throws IOException
47 {
48 for ( int x = 0; x < len; x++ )
49 {
50 int c = b[off + x];
51 if ( last == '\n' || ( last == '\r' && c != '\n' ) )
52 {
53 out.write( b, off, x );
54 bout.write( b, off, x );
55 out.write( indent );
56 off += x;
57 len -= x;
58 x = 0;
59 }
60 last = c;
61 }
62 out.write( b, off, len );
63 bout.write( b, off, len );
64 }
65
66 public void write( int b )
67 throws IOException
68 {
69 if ( last == '\n' || ( last == '\r' && b != '\n' ) )
70 {
71 out.write( indent );
72 }
73 out.write( b );
74 bout.write( b );
75 last = b;
76 }
77
78 public String toString()
79 {
80 return bout.toString();
81 }
82
83 public String getContent()
84 {
85 return bout.toString();
86 }
87
88 }