Skip to content

Instantly share code, notes, and snippets.

@ikai
Created October 22, 2009 03:43
Show Gist options
  • Save ikai/215717 to your computer and use it in GitHub Desktop.
Save ikai/215717 to your computer and use it in GitHub Desktop.
private byte[] getByteArrayFromInputStream(InputStream stream) throws IOException {
byte[] bytes;
int len;
byte[] buffer = new byte[8192];
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
while ((len = stream.read(buffer, 0, buffer.length)) != -1) output.write(buffer, 0, len);
bytes = output.toByteArray();
} finally {
output.close();
}
return bytes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment