forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWrappedResponseInputStream.java
More file actions
80 lines (60 loc) · 1.81 KB
/
Copy pathWrappedResponseInputStream.java
File metadata and controls
80 lines (60 loc) · 1.81 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package com.github.dockerjava.jaxrs.util;
import java.io.IOException;
import java.io.InputStream;
import javax.ws.rs.core.Response;
/**
* This is a wrapper around {@link Response} that acts as a {@link InputStream}. When this {@link WrappedResponseInputStream} is closed it
* closes the underlying {@link Response} object also to prevent blocking/hanging connections.
*
* @author Marcus Linke
*/
public class WrappedResponseInputStream extends InputStream {
private Response response;
private InputStream delegate;
private boolean closed = false;
public WrappedResponseInputStream(Response response) {
this.response = response;
this.delegate = response.readEntity(InputStream.class);
}
public int read() throws IOException {
return delegate.read();
}
public int hashCode() {
return delegate.hashCode();
}
public int read(byte[] b) throws IOException {
return delegate.read(b);
}
public boolean equals(Object obj) {
return delegate.equals(obj);
}
public int read(byte[] b, int off, int len) throws IOException {
return delegate.read(b, off, len);
}
public long skip(long n) throws IOException {
return delegate.skip(n);
}
public int available() throws IOException {
return delegate.available();
}
public void close() throws IOException {
if (closed) {
return;
}
closed = true;
delegate.close();
response.close();
}
public void mark(int readlimit) {
delegate.mark(readlimit);
}
public void reset() throws IOException {
delegate.reset();
}
public boolean markSupported() {
return delegate.markSupported();
}
public boolean isClosed() {
return closed;
}
}