blob: ac0f165d8e0ccdd285b62959d1cfe4a837ce358b (
plain)
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
|
package org.zwobble.mammoth.internal.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class Streams {
private Streams() {}
public static void copy(InputStream source, OutputStream destination) throws IOException {
byte[] buffer = new byte[4096];
while (true) {
int bytesRead = source.read(buffer);
if (bytesRead == -1) {
return;
}
destination.write(buffer, 0, bytesRead);
}
}
public static byte[] toByteArray(InputStream stream) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(stream, output);
return output.toByteArray();
}
}
|