Java InputStream Read All readAllBuffer(InputStream stream, byte[] buffer)

Here you can find the source of readAllBuffer(InputStream stream, byte[] buffer)

Description

read All Buffer

License

Open Source License

Declaration

public static int readAllBuffer(InputStream stream, byte[] buffer) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static int readAllBuffer(InputStream stream, byte[] buffer) throws IOException {
        return readAllBuffer(stream, buffer, 0, buffer.length);
    }//from   w w w  . j  a  v  a  2s. c o m

    public static int readAllBuffer(InputStream stream, byte[] buffer, int off, int len) throws IOException {
        int total = 0;
        do {
            int l = len - total;
            int nb = stream.read(buffer, off, l);
            if (nb <= 0)
                return total;
            off += nb;
            total += nb;
        } while (total < len);
        return total;
    }
}

Related

  1. readAll(InputStream inputStream)
  2. readAll(InputStream is)
  3. readAll(InputStream is, byte[] buffer, int offset, int length)
  4. readAll(InputStream stream)
  5. readAll(InputStream stream)
  6. readAllFrom(java.io.InputStream is)
  7. readAllFromStream(InputStream is)
  8. readAllInString(InputStream in)