Coverage Report - org.apache.maven.wagon.providers.webdav.PutInputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
PutInputStream
85% 
100% 
1.25
 
 1  
 package org.apache.maven.wagon.providers.webdav;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2006 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 java.io.File;
 20  
 import java.io.FileInputStream;
 21  
 import java.io.FileNotFoundException;
 22  
 import java.io.IOException;
 23  
 
 24  
 import org.apache.maven.wagon.Wagon;
 25  
 import org.apache.maven.wagon.events.TransferEvent;
 26  
 import org.apache.maven.wagon.events.TransferEventSupport;
 27  
 import org.apache.maven.wagon.resource.Resource;
 28  
 
 29  
 /**
 30  
  * Put Input Stream is borrowed from wagon-http, and is used to properly
 31  
  * notify the listeners of transfer events on a put request.
 32  
  * 
 33  
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
 34  
  */
 35  
 public class PutInputStream
 36  
     extends FileInputStream
 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  43
         super( file );
 46  
 
 47  43
         this.eventSupport = eventSupport;
 48  
 
 49  43
         event = new TransferEvent( wagon, resource, TransferEvent.TRANSFER_PROGRESS, TransferEvent.REQUEST_PUT );
 50  
 
 51  43
         event.setLocalFile( file );
 52  43
     }
 53  
 
 54  
     public int read( byte buffer[] )
 55  
         throws IOException
 56  
     {
 57  2
         return read( buffer, 0, buffer.length );
 58  
     }
 59  
 
 60  
     public int read()
 61  
         throws IOException
 62  
     {
 63  0
         byte buffer[] = new byte[1];
 64  
 
 65  0
         return read( buffer );
 66  
     }
 67  
 
 68  
     public int read( byte buffer[], int offset, int length )
 69  
         throws IOException
 70  
     {
 71  44
         int retValue = super.read( buffer, offset, length );
 72  
 
 73  44
         if ( retValue > 0 )
 74  
         {
 75  43
             event.setTimestamp( System.currentTimeMillis() );
 76  
 
 77  43
             eventSupport.fireTransferProgress( event, buffer, retValue );
 78  
         }
 79  44
         return retValue;
 80  
     }
 81  
 }