Coverage Report - org.kuali.maven.wagon.TransferProgressFileOutputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
TransferProgressFileOutputStream
0%
0/16
0%
0/2
1.25
 
 1  
 /*
 2  
  * Copyright 2004-2007 the original author or authors.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.maven.wagon;
 17  
 
 18  
 import java.io.File;
 19  
 import java.io.FileNotFoundException;
 20  
 import java.io.FileOutputStream;
 21  
 import java.io.IOException;
 22  
 
 23  
 /**
 24  
  * An extension to the {@link FileOutputStream} that notifies
 25  
  * a @{link TransferProgress} object as it is being written to.
 26  
  *
 27  
  * @author Ben Hale
 28  
  * @since 1.1
 29  
  */
 30  
 class TransferProgressFileOutputStream extends FileOutputStream {
 31  
 
 32  
     private TransferProgress progress;
 33  
 
 34  
     public TransferProgressFileOutputStream(File file, TransferProgress progress) throws FileNotFoundException {
 35  0
         super(file);
 36  0
         this.progress = progress;
 37  0
     }
 38  
 
 39  
     public void write(int b) throws IOException {
 40  0
         super.write(b);
 41  0
         progress.notify(new byte[]{(byte) b}, 1);
 42  0
     }
 43  
 
 44  
     public void write(byte b[]) throws IOException {
 45  0
         super.write(b);
 46  0
         progress.notify(b, b.length);
 47  0
     }
 48  
 
 49  
     public void write(byte b[], int off, int len) throws IOException {
 50  0
         super.write(b, off, len);
 51  0
         if (off == 0) {
 52  0
             progress.notify(b, len);
 53  
         } else {
 54  0
             byte[] bytes = new byte[len];
 55  0
             System.arraycopy(b, off, bytes, 0, len);
 56  0
             progress.notify(bytes, len);
 57  
         }
 58  0
     }
 59  
 }