Coverage Report - org.apache.maven.shared.release.exec.RawStreamPumper
 
Classes in this File Line Coverage Branch Coverage Complexity
RawStreamPumper
78%
30/38
64%
9/14
2,333
 
 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.IOException;
 23  
 import java.io.InputStream;
 24  
 import java.io.OutputStream;
 25  
 
 26  
 public class RawStreamPumper
 27  
     extends Thread 
 28  
 {
 29  
     private InputStream in;
 30  
 
 31  
     private OutputStream out;
 32  
 
 33  
     boolean done;
 34  
     
 35  
     boolean poll;
 36  
     
 37  24
     byte buffer[] = new byte[256];
 38  
 
 39  
     public RawStreamPumper( InputStream in , OutputStream out, boolean poll )
 40  8
     {
 41  8
         this.in = in;
 42  8
         this.out = out;
 43  8
         this.poll = poll;
 44  8
     }
 45  
 
 46  
     public RawStreamPumper( InputStream in , OutputStream out )
 47  16
     {
 48  16
         this.in = in;
 49  16
         this.out = out;
 50  16
         this.poll = false;
 51  16
     }
 52  
 
 53  
     public void setDone()
 54  
     {
 55  24
         done = true;
 56  24
     }
 57  
 
 58  
     public void closeInput() 
 59  
         throws IOException
 60  
     {
 61  16
         in.close();
 62  16
     }
 63  
 
 64  
     public void closeOutput()
 65  
         throws IOException
 66  
     {
 67  8
         out.close();
 68  8
     }
 69  
 
 70  
     public void run()
 71  
     {
 72  
         try
 73  
         {
 74  24
             if ( poll )
 75  
             {
 76  25
                 while ( !done )
 77  
                 {
 78  17
                     if ( in.available() > 0 )
 79  
                     {
 80  0
                         int i = in.read( buffer );
 81  0
                         if ( i != -1 )
 82  
                         {
 83  0
                             out.write( buffer, 0, i );
 84  0
                             out.flush();
 85  
                         }
 86  
                         else
 87  
                         {
 88  0
                             done = true;
 89  
                         }
 90  0
                     }
 91  
                     else
 92  
                     {
 93  17
                         Thread.sleep( 1 );
 94  
                     }
 95  
                 }
 96  
             }
 97  
             else
 98  
             {
 99  16
                 int i = in.read( buffer );
 100  160
                 while ( i != -1 && !done )
 101  
                 {
 102  144
                     if ( i != -1 )
 103  
                     {
 104  144
                         out.write( buffer, 0, i );
 105  144
                         out.flush();
 106  
                     }
 107  
                     else
 108  
                     {
 109  0
                         done = true;
 110  
                     }
 111  144
                     i = in.read( buffer );
 112  
                 }
 113  
             }
 114  
         }
 115  0
         catch ( Throwable e )
 116  
         {
 117  
             // Catched everything
 118  
         }
 119  
         finally
 120  
         {
 121  24
             done = true;
 122  24
         }
 123  24
     }
 124  
 }