Reads the given input stream and returns its content as a byte array. @param inputStream an input stream. @param close true to close the input stream after reading. @return the content of the given input stream. @throws IOException if a problem occurs during reading.
(final InputStream inputStream, final boolean close)
| 295 | * @throws IOException if a problem occurs during reading. |
| 296 | */ |
| 297 | private static byte[] readStream(final InputStream inputStream, final boolean close) |
| 298 | throws IOException { |
| 299 | if (inputStream == null) { |
| 300 | throw new IOException("Class not found"); |
| 301 | } |
| 302 | try { |
| 303 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); |
| 304 | byte[] data = new byte[INPUT_STREAM_DATA_CHUNK_SIZE]; |
| 305 | int bytesRead; |
| 306 | while ((bytesRead = inputStream.read(data, 0, data.length)) != -1) { |
| 307 | outputStream.write(data, 0, bytesRead); |
| 308 | } |
| 309 | outputStream.flush(); |
| 310 | return outputStream.toByteArray(); |
| 311 | } finally { |
| 312 | if (close) { |
| 313 | inputStream.close(); |
| 314 | } |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | // ----------------------------------------------------------------------------------------------- |
| 319 | // Accessors |
no test coverage detected