• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

box / box-java-sdk / #3909

12 Jul 2024 01:30PM CUT coverage: 72.476% (+0.04%) from 72.438%
#3909

Pull #1258

github

web-flow
Merge 6eb7aa968 into f08844889
Pull Request #1258: test: Add test for uploading file using stream

7681 of 10598 relevant lines covered (72.48%)

0.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/box/sdk/ProgressInputStream.java
1
package com.box.sdk;
2

3
import java.io.IOException;
4
import java.io.InputStream;
5

6
/**
7
 * An {@link InputStream} that can report the progress of reading from another InputStream to a
8
 * {@link ProgressListener}.
9
 */
10
class ProgressInputStream extends InputStream {
11
    private final InputStream stream;
12
    private final ProgressListener listener;
13

14
    private long total;
15
    private long totalRead;
16
    private int progress;
17

18
    /**
19
     * Constructs a ProgressInputStream that wraps another InputStream.
20
     *
21
     * @param stream   the stream whose progress will be monitored.
22
     * @param listener the listener that will receive progress updates.
23
     * @param total    the total number of bytes that are expected to be read from the stream.
24
     */
25
    ProgressInputStream(InputStream stream, ProgressListener listener, long total) {
×
26
        this.stream = stream;
×
27
        this.listener = listener;
×
28
        this.total = total;
×
29
    }
×
30

31
    /**
32
     * Gets the total number of bytes that are expected to be read from the stream.
33
     *
34
     * @return the total number of bytes.
35
     */
36
    public long getTotal() {
37
        return this.total;
×
38
    }
39

40
    /**
41
     * Sets the total number of bytes that are expected to be read from the stream.
42
     *
43
     * @param total the total number of bytes
44
     */
45
    public void setTotal(long total) {
46
        this.total = total;
×
47
    }
×
48

49
    @Override
50
    public void close() throws IOException {
51
        this.stream.close();
×
52
    }
×
53

54
    @Override
55
    public int read() throws IOException {
56
        int read = this.stream.read();
×
57
        this.totalRead++;
×
58
        this.listener.onProgressChanged(this.totalRead, this.total);
×
59

60
        return read;
×
61
    }
62

63
    @Override
64
    public int read(byte[] b, int off, int len) throws IOException {
65
        int read = this.stream.read(b, off, len);
×
66
        this.totalRead += read;
×
67
        this.listener.onProgressChanged(this.totalRead, this.total);
×
68

69
        return read;
×
70
    }
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc