Skip to content

Instantly share code, notes, and snippets.

@ae6rt
Last active August 22, 2018 17:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ae6rt/8243544 to your computer and use it in GitHub Desktop.
Save ae6rt/8243544 to your computer and use it in GitHub Desktop.
Java: drain an inputstream of bytes
private byte[] drainInputStream(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
baos.write(buffer, 0, bytesRead);
}
return baos.toByteArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment