How do I read an entire InputStream
into a byte array?
Java 8 way (thanks to BufferedReader and Adam Bien)
private static byte[] readFully(InputStream input) throws IOException {
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) {
return buffer.lines().collect(Collectors.joining("\n")).getBytes();
}
}
Note that this solution wipes carriage return ('\r') and can be inappropriate.