Last active
August 22, 2018 17:36
-
-
Save ae6rt/8243544 to your computer and use it in GitHub Desktop.
Java: drain an inputstream of bytes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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