Read an input stream into a byte[]
(InputStream is)
| 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 |