forked from qiniu/java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOUtils.java
More file actions
34 lines (27 loc) · 888 Bytes
/
Copy pathIOUtils.java
File metadata and controls
34 lines (27 loc) · 888 Bytes
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
package com.qiniu.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
public class IOUtils {
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
private IOUtils() {
}
/**
* 输入InputSteam,返回byte[].
* 参考:https://github.com/apache/commons-io/blob/master/src/main/java/org/apache/commons/io/IOUtils.java<br>
*
* @param input
* @return
* @throws IOException
*/
public static byte[] toByteArray(final InputStream input) throws IOException {
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
int n;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
}
return output.toByteArray();
}
}
}