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 import com.amazonaws.services.s3.internal.RepeatableFileInputStream;
24
25
26
27
28
29
30
31 public class TransferProgressFileInputStream extends RepeatableFileInputStream {
32
33 private TransferProgress progress;
34
35 public TransferProgressFileInputStream(File file, TransferProgress progress) throws FileNotFoundException {
36 super(file);
37 this.progress = progress;
38 }
39
40 @Override
41 public int read() throws IOException {
42 int b = super.read();
43 if (b != -1) {
44 progress.notify(new byte[] { (byte) b }, 1);
45 }
46 return b;
47 }
48
49 @Override
50 public int read(byte b[]) throws IOException {
51 int length = super.read(b);
52 if (length != -1) {
53 progress.notify(b, length);
54 }
55 return length;
56 }
57
58 @Override
59 public int read(byte b[], int off, int len) throws IOException {
60 int count = super.read(b, off, len);
61 if (count == -1) {
62 return count;
63 }
64 if (off == 0) {
65 progress.notify(b, count);
66 } else {
67 byte[] bytes = new byte[len];
68 System.arraycopy(b, off, bytes, 0, count);
69 progress.notify(bytes, count);
70 }
71 return count;
72 }
73 }