-
Notifications
You must be signed in to change notification settings - Fork 10
/
DeferredFilePathInputStream.java
63 lines (49 loc) · 1.05 KB
/
DeferredFilePathInputStream.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.jenkinsci.plugins.codedx;
import hudson.FilePath;
import java.io.IOException;
import java.io.InputStream;
public class DeferredFilePathInputStream extends InputStream {
FilePath fp;
InputStream is;
public DeferredFilePathInputStream(FilePath fp)
{
this.fp = fp;
this.is = null;
}
private void initStream() throws IOException {
if (this.is == null) {
try {
this.is = fp.read();
} catch (InterruptedException e) {
throw new IOException("Operation was interrupted", e);
}
}
}
@Override
public int read(byte[] b) throws IOException {
initStream();
int numRead = this.is.read(b);
if (numRead < b.length) {
this.is.close();
}
return numRead;
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
initStream();
int numRead = this.is.read(b, off, len);
if (numRead < len) {
this.is.close();
}
return numRead;
}
@Override
public int read() throws IOException {
initStream();
int result = this.is.read();
if (result < 0) {
this.is.close();
}
return result;
}
}