Java Utililty Methods InputStream Read All

List of utility methods to do InputStream Read All

Description

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

Method

byte[]readAll(final InputStream is)
Read all data from input stream
int dataLength = 0;
int byteOffset = 0;
int blockSize = 8000;
byte[] buffer = null;
do {
    byte[] tmpBuf = new byte[blockSize];
    dataLength = is.read(tmpBuf, 0, tmpBuf.length);
    if (dataLength != -1) {
...
intreadAll(InputStream i, byte b[])
Reads until the array is full or until the stream ends
int len = b.length;
int n = 0;
while (n < len) {
    int count = i.read(b, n, len - n);
    if (count < 0) {
        return n;
    n += count;
...
byte[]readAll(InputStream in)
read All
byte[] result = new byte[in.available()];
in.read(result);
return result;
byte[]readall(InputStream in)
readall
byte[] buf = new byte[4096];
int off = 0;
while (true) {
    if (off == buf.length) {
        byte[] n = new byte[buf.length * 2];
        System.arraycopy(buf, 0, n, 0, buf.length);
        buf = n;
    int ret = in.read(buf, off, buf.length - off);
    if (ret < 0) {
        byte[] n = new byte[off];
        System.arraycopy(buf, 0, n, 0, off);
        return (n);
    off += ret;
byte[]readAll(InputStream in)
Read an entire stream and return byte[].
final int CHUNK = 16 * 1024;
int total = 0;
byte[] buf = new byte[CHUNK * 2];
int read = in.read(buf);
if (read > 0)
    total += read;
while (read != -1) {
    if (buf.length - total < CHUNK) {
...
byte[]readAll(InputStream in)
Reads all data from the given input stream.
return readAll(in, DEFAULT_BUFFER_SIZE);
StringreadAll(InputStream in)
Read all bytes available on the input stream, and concatenates them into a string.
StringBuilder bob = new StringBuilder();
int c;
while ((c = in.read()) != -1) {
    bob.append((char) c);
return bob.toString();
StringreadAll(InputStream in)
read All
StringBuffer b = new StringBuffer();
int c;
while ((c = in.read()) != -1) {
    b.append((char) c);
return b.toString();
intreadAll(InputStream in, byte[] buffer, int off, int len)
Continue reading from a stream until EOF is reached, or the requested number of bytes is read.
int soFar = 0;
while (soFar < len) {
    int n = in.read(buffer, off + soFar, len - soFar);
    if (n < 0) {
        return soFar;
    soFar += n;
return len;
intreadall(InputStream in, byte[] buffer, int offset, int len)
Receives data.
int total = 0;
for (;;) {
    int received = in.read(buffer, offset, len);
    if (received < 0) {
        return total;
    total += received;
    offset += received;
...