1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.maven.wagon;
17  
18  import java.io.File;
19  import java.io.FileInputStream;
20  import java.io.FileNotFoundException;
21  import java.io.IOException;
22  
23  
24  
25  
26  
27  
28  
29  public class TransferProgressFileInputStream extends FileInputStream {
30  
31  	private TransferProgress progress;
32  
33  	public TransferProgressFileInputStream(File file, TransferProgress progress) throws FileNotFoundException {
34  		super(file);
35  		this.progress = progress;
36  	}
37  
38  	public int read() throws IOException {
39  		int b = super.read();
40  		if (b != -1) {
41  			progress.notify(new byte[] { (byte) b }, 1);
42  		}
43  		return b;
44  	}
45  
46  	public int read(byte b[]) throws IOException {
47  		int length = super.read(b);
48  		if (length != -1) {
49  			progress.notify(b, length);
50  		}
51  		return length;
52  	}
53  
54  	public int read(byte b[], int off, int len) throws IOException {
55  		int count = super.read(b, off, len);
56  		if (count == -1) {
57  			return count;
58  		}
59  		if (off == 0) {
60  			progress.notify(b, count);
61  		} else {
62  			byte[] bytes = new byte[len];
63  			System.arraycopy(b, off, bytes, 0, count);
64  			progress.notify(bytes, count);
65  		}
66  		return count;
67  	}
68  }