Reads all bytes from an input stream into a byte array. Does not close the stream. @param in the input stream to read from @return a byte array containing all the bytes from the stream @throws IOException if an I/O error occurs
(InputStream in)
| 164 | |
| 165 | |
| 166 | public static byte[] toByteArray(InputStream in) throws IOException { |
| 167 | // Presize the ByteArrayOutputStream since we know how large it will need |
| 168 | // to be, unless that value is less than the default ByteArrayOutputStream |
| 169 | // size (32). |
| 170 | ByteArrayOutputStream out = new ByteArrayOutputStream(Math.max(32, in.available())); |
| 171 | copy(in, out); |
| 172 | return out.toByteArray(); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Reads all bytes from an input stream into a byte array. The given expected size is used to |