Siphon.java
1.33 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.granite.auth.saml.util.io;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Siphon {
private int bufferSize;
private boolean closeStreams;
public Siphon() {
this(true);
}
public Siphon(boolean closeStreams) {
this(closeStreams, 8192);
}
public Siphon(boolean closeStreams, int bufferSize) {
if (bufferSize < 1) {
throw new IllegalArgumentException("Buffer size must be greater than 0");
}
this.bufferSize = bufferSize;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void siphon(InputStream in, OutputStream out) throws IOException {
if (null == in) {
throw new IllegalArgumentException("InputStream is required.");
}
if (null == out) {
throw new IllegalArgumentException("OutputStream is required.");
}
try {
int read;
byte[] buffer = new byte[this.bufferSize];
while (-1 != (read = in.read(buffer))) {
out.write(buffer, 0, read);
}
}
finally {
if (this.closeStreams) {
in.close();
out.close();
}
}
}
}