Coverage Report - org.apache.maven.shared.release.exec.TeeOutputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
TeeOutputStream
78%
22/28
50%
7/14
2,167
 
 1  
 package org.apache.maven.shared.release.exec;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 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  22
     private ByteArrayOutputStream bout = new ByteArrayOutputStream( 1024 * 8 );
 31  
     private byte indent[];
 32  22
     private int last = '\n';
 33  
 
 34  
     public TeeOutputStream( OutputStream out )
 35  
     {
 36  20
         this( out, "    " );
 37  20
     }
 38  
     
 39  
     public TeeOutputStream( OutputStream out, String i )
 40  
     {
 41  22
         super( out );
 42  22
         indent = i.getBytes();
 43  22
     }
 44  
 
 45  
     public void write( byte[] b, int off, int len )
 46  
         throws IOException
 47  
     {
 48  198
         for ( int x = 0; x < len; x++ )
 49  
         {
 50  52
             int c = b[off + x];
 51  52
             if ( last == '\n' || ( last == '\r' && c != '\n' ) )
 52  
             {
 53  6
                 out.write( b, off, x );
 54  6
                 bout.write( b, off, x );
 55  6
                 out.write( indent );
 56  6
                 off += x;
 57  6
                 len -= x;
 58  6
                 x = 0;
 59  
             }
 60  52
             last = c;
 61  
         }
 62  146
         out.write( b, off, len );
 63  146
         bout.write( b, off, len );
 64  146
     }
 65  
 
 66  
     public void write( int b )
 67  
         throws IOException
 68  
     {
 69  0
         if ( last == '\n' || ( last == '\r' && b != '\n' ) )
 70  
         {
 71  0
             out.write( indent );
 72  
         }
 73  0
         out.write( b );
 74  0
         bout.write( b );
 75  0
         last = b;
 76  0
     }
 77  
     
 78  
     public String toString() 
 79  
     {
 80  20
         return bout.toString();
 81  
     }
 82  
 
 83  
     public String getContent()
 84  
     {
 85  2
         return bout.toString();
 86  
     }
 87  
 
 88  
 }