MCPcopy Create free account
hub / github.com/0opslab/opslabJutil / stream2Byte

Method stream2Byte

src/main/java/com/opslab/util/StreamUtil.java:24–33  ·  view source on GitHub ↗

Read an input stream into a byte[]

(InputStream is)

Source from the content-addressed store, hash-verified

22 * Read an input stream into a byte[]
23 */
24 public static final byte[] stream2Byte(InputStream is) throws IOException {
25 ByteArrayOutputStream baos = new ByteArrayOutputStream();
26 int len = 0;
27 byte[] b = new byte[1024];
28 while ((len = is.read(b, 0, b.length)) != -1) {
29 baos.write(b, 0, len);
30 }
31 byte[] buffer = baos.toByteArray();
32 return buffer;
33 }
34
35 /**
36 * InputStream 转为 byte

Callers 1

testStream2ByteMethod · 0.95

Calls 2

writeMethod · 0.45
toByteArrayMethod · 0.45

Tested by 1

testStream2ByteMethod · 0.76