Java Utililty Methods InputStream to Byte Array

List of utility methods to do InputStream to Byte Array

Description

The list of methods to do InputStream to Byte Array are organized into topic(s).

Method

byte[]getBytes(InputStream input)
Drains the given InputStream of all data and returns a byte array which contains all of that data.
return getOutput(input).toByteArray();
byte[]getBytes(InputStream input)
get Bytes
byte[] buffer = new byte[8 * 1024];
int count;
ByteArrayOutputStream output = new ByteArrayOutputStream();
while ((count = input.read(buffer, 0, buffer.length)) != -1) {
    output.write(buffer, 0, count);
return output.toByteArray();
byte[]getBytes(InputStream input)
get Bytes
ByteArrayOutputStream result = new ByteArrayOutputStream();
copy(input, result);
result.close();
return result.toByteArray();
byte[]getBytes(InputStream input)
get Bytes
ByteArrayOutputStream result = new ByteArrayOutputStream();
copy(input, result);
result.close();
return result.toByteArray();
byte[]getBytes(InputStream inputStream)
get Bytes
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024);
byte[] block = new byte[4096];
while (true) {
    int readLength = bufferedInputStream.read(block);
    if (readLength == -1)
        break;
    byteArrayOutputStream.write(block, 0, readLength);
...
byte[]getBytes(InputStream inputStream)
get Bytes
try {
    byte[] buffer = new byte[4096];
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    for (int count = inputStream.read(buffer); count >= 0; count = inputStream.read(buffer)) {
        out.write(buffer, 0, count);
    byte[] bytes = out.toByteArray();
    return bytes;
...
byte[]getBytes(InputStream inputStream)
get Bytes
assert null != inputStream;
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int numberRead;
byte[] data = new byte[BUFFER_SIZE];
while ((numberRead = inputStream.read(data, 0, data.length)) != -1) {
    buffer.write(data, 0, numberRead);
buffer.flush();
...
byte[]getBytes(InputStream inputStream)
get Bytes
try {
    byte[] buffer = new byte[4096];
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    for (int count = inputStream.read(buffer); count >= 0; count = inputStream.read(buffer)) {
        out.write(buffer, 0, count);
    byte[] bytes = out.toByteArray();
    return bytes;
...
byte[]getBytes(InputStream is)
get Bytes
int len;
int size = 1024;
byte[] buf;
if (is instanceof ByteArrayInputStream) {
    size = is.available();
    buf = new byte[size];
    len = is.read(buf, 0, size);
} else {
...
byte[]getBytes(InputStream is)
get Bytes
int len;
int size = 1024;
byte[] buf;
if (is instanceof ByteArrayInputStream) {
    size = is.available();
    buf = new byte[size];
    len = is.read(buf, 0, size);
} else {
...