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

StringreadAll(InputStream inputStream)
read All
StringBuilder result = new StringBuilder();
BufferedInputStream buffered = new BufferedInputStream(inputStream);
int i;
while ((i = buffered.read()) != -1) {
    result.append((char) i);
return result.toString();
byte[]readAll(InputStream is)
read All
int pos = 0;
byte[] buffer = new byte[1024];
while (true) {
    int toRead;
    if (pos >= buffer.length) {
        toRead = buffer.length * 2;
        if (buffer.length < pos + toRead) {
            buffer = Arrays.copyOf(buffer, pos + toRead);
...
intreadAll(InputStream is, byte[] buffer, int offset, int length)
read All
int readLength = 0;
while (length > 0) {
    int sublen = is.read(buffer, offset, length);
    if (sublen <= 0) {
        return readLength;
    length -= sublen;
    offset += sublen;
...
StringreadAll(InputStream stream)
Reads the entire content of a stream to a string.
Scanner scanner = new Scanner(stream).useDelimiter("\\A");
return scanner.hasNext() ? scanner.next() : null;
Object[]readAll(InputStream stream)
deserializes from the given stream and returns the object from it.
ObjectInputStream ois;
Vector<Object> result;
if (!(stream instanceof BufferedInputStream)) {
    stream = new BufferedInputStream(stream);
ois = new ObjectInputStream(stream);
result = new Vector<Object>();
try {
...
intreadAllBuffer(InputStream stream, byte[] buffer)
read All Buffer
return readAllBuffer(stream, buffer, 0, buffer.length);
byte[]readAllFrom(java.io.InputStream is)
Reads an input stream til EOF and returns all bytes read.
byte[] buf = new byte[8192];
int i = 0;
int n = 0, r;
final int SIZE = 4096;
while (true) {
    while (buf.length <= n + SIZE + 1)
        buf = resizeVec(buf, 2 * buf.length);
    r = is.read(buf, n, SIZE);
...
byte[]readAllFromStream(InputStream is)
read All From Stream
DataInputStream dis = new DataInputStream(is);
byte[] buffer = new byte[4096];
int totalBytesRead = 0, bytesRead;
while ((bytesRead = dis.read(buffer, totalBytesRead, buffer.length - totalBytesRead)) >= 0) {
    if (totalBytesRead + bytesRead >= buffer.length) {
        byte[] oldBuffer = buffer;
        buffer = new byte[oldBuffer.length * 2];
        System.arraycopy(oldBuffer, 0, buffer, 0, oldBuffer.length);
...
StringreadAllInString(InputStream in)
read All In String
return new String(readAll(in));