Coverage Report - org.apache.maven.wagon.providers.http.PutInputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
PutInputStream
85% 
100% 
1.25
 
 1  
 package org.apache.maven.wagon.providers.http;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.apache.maven.wagon.Wagon;
 20  
 import org.apache.maven.wagon.events.TransferEvent;
 21  
 import org.apache.maven.wagon.events.TransferEventSupport;
 22  
 import org.apache.maven.wagon.resource.Resource;
 23  
 
 24  
 import java.io.File;
 25  
 import java.io.FileInputStream;
 26  
 import java.io.FileNotFoundException;
 27  
 import java.io.IOException;
 28  
 
 29  
 
 30  
 /**
 31  
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
 32  
  * @version $Id: PutInputStream.java 162476 2005-04-19 02:49:45Z brett $
 33  
  */
 34  
 public class PutInputStream
 35  
     extends FileInputStream
 36  
 {
 37  
 
 38  
     private TransferEventSupport eventSupport;
 39  
 
 40  
     private TransferEvent event;
 41  
 
 42  
     public PutInputStream( File file, Resource resource, Wagon wagon, TransferEventSupport eventSupport )
 43  
         throws FileNotFoundException
 44  
     {
 45  6
         super( file );
 46  
 
 47  6
         this.eventSupport = eventSupport;
 48  
 
 49  6
         event = new TransferEvent( wagon, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_PUT );
 50  
 
 51  6
         event.setLocalFile( file );
 52  
 
 53  6
     }
 54  
 
 55  
 
 56  
     public int read( byte b[] )
 57  
         throws IOException
 58  
     {
 59  12
         return read( b, 0, b.length );
 60  
 
 61  
     }
 62  
 
 63  
     public int read()
 64  
         throws IOException
 65  
     {
 66  0
         byte b[] = new byte[1];
 67  
 
 68  0
         return read( b );
 69  
 
 70  
     }
 71  
 
 72  
     public int read( byte b[], int off, int len )
 73  
         throws IOException
 74  
     {
 75  12
         int retValue = super.read( b, off, len );
 76  
 
 77  12
         if ( retValue > 0 )
 78  
         {
 79  6
             event.setTimestamp( System.currentTimeMillis() );
 80  
 
 81  6
             eventSupport.fireTransferProgress( event, b, retValue );
 82  
         }
 83  12
         return retValue;
 84  
     }
 85  
 
 86  
 }