Java Utililty Methods InputStream Read Bytes

List of utility methods to do InputStream Read Bytes

Description

The list of methods to do InputStream Read Bytes are organized into topic(s).

Method

byte[]readBytes(InputStream inputStream, int bufSize)
read Bytes
byte[] buf = new byte[bufSize];
byte[] data = new byte[0];
int length = 0;
while ((length = inputStream.read(buf)) > 0) {
    int oldLength = data.length;
    byte[] temp = new byte[oldLength];
    System.arraycopy(data, 0, temp, 0, oldLength);
    data = new byte[length + oldLength];
...
byte[]readBytes(InputStream inputStream, int length)
read Bytes
byte[] buffer = new byte[length];
int bytesRead = 0;
int limit = 0;
while (limit < length && bytesRead != -1) {
    bytesRead = inputStream.read(buffer, limit, length - limit);
    limit += bytesRead;
if (limit < length) {
...
byte[]readBytes(InputStream inputStream, int numberOfBytes)
read Bytes
byte[] readBytes = new byte[numberOfBytes];
inputStream.read(readBytes);
return readBytes;
byte[]readBytes(InputStream inputStream, int numberOfBytes)
read Bytes
byte[] readBytes = new byte[numberOfBytes];
inputStream.read(readBytes);
return readBytes;
intreadBytes(InputStream ins, byte[] buf, int size)
Read size bytes from stream into buf.
int off = 0;
while (off < size) {
    int nread = ins.read(buf, off, size - off);
    if (nread == -1) {
        return off;
    off += nread;
return off;
byte[]readBytes(InputStream is)
read Bytes
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
try {
    byte[] transfer = new byte[1024];
    int read = -1;
    while ((read = is.read(transfer)) > 0) {
        bytesOut.write(transfer, 0, read);
} finally {
...
byte[]readBytes(InputStream is)
read Bytes
try {
    int size = is.available();
    byte[] buf = new byte[size];
    is.read(buf);
    return buf;
} catch (Exception e) {
    e.printStackTrace();
return null;
byte[]readBytes(InputStream is)
read Bytes
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (InputStream bis = new BufferedInputStream(is)) {
    int b;
    while ((b = bis.read()) >= 0) {
        bos.write(b);
} catch (IOException e) {
    throw new IllegalStateException(e);
...
byte[]readBytes(InputStream is)
read Bytes
BufferedInputStream bufin = new BufferedInputStream(is);
int buffSize = 1024;
ByteArrayOutputStream out = new ByteArrayOutputStream(buffSize);
byte[] temp = new byte[buffSize];
int size = 0;
try {
    while ((size = bufin.read(temp)) != -1) {
        out.write(temp, 0, size);
...
byte[]readBytes(InputStream is)
read Bytes
ByteArrayOutputStream bs = new ByteArrayOutputStream();
@SuppressWarnings("unused")
long size = copyStream(is, bs);
return bs.toByteArray();