public static byte[] getBytesFromInputStream(InputStream is) throws IOException {
OutputStreamByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buffer = new byte[0xFFFF];
for (int len = is.read(buffer); len != -1; len = is.read(buffer)) {
os.write(buffer, 0, len);
}
return os.toByteArray();
}
Edit by Boris Schegolev was not correct: the code will not compile, since OutputStream does not have toByteArray method.
Boris Schegolev
- 3.7k
- 5
- 23
- 35
fixed the code to make it working, improved formatting to follow common IDE conventions
kritzikratzi
- 20.3k
- 1
- 31
- 40