/** * Reads all the data from the given input stream. * * @param input Input stream to read. * @param sizeHint Estimate of amount of data to be read in bytes. * * @return Byte array of data read from stream. * * @throws StreamException on stream IO errors. */ public static byte[] readAll(final InputStream input, final int sizeHint) throws StreamException { final ByteArrayOutputStream output = new ByteArrayOutputStream(sizeHint); try { Streams.pipeAll(input, output); } catch (IOException e) { throw new StreamException(e); } finally { closeStream(input); closeStream(output); } return output.toByteArray(); }
/** * Reads all the data from the given file. * * @param file File to read. * * @return Byte array of data read from file. * * @throws StreamException on stream IO errors. */ public static byte[] readAll(final File file) throws StreamException { final InputStream input = makeStream(file); try { return readAll(input, (int) file.length()); } finally { closeStream(input); } }