Java InputStream Read All readAll(InputStream in)

Here you can find the source of readAll(InputStream in)

Description

Read all bytes available on the input stream, and concatenates them into a string.

License

Open Source License

Declaration

public static final String readAll(InputStream in) 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 {
    /**/*from w  ww . j  a va2 s.  c  om*/
     * Read all bytes available on the input stream, and concatenates them into a string.
     * N.B. This casts bytes read directly to characters.
     */
    public static final String readAll(InputStream in) throws IOException {
        StringBuilder bob = new StringBuilder();
        int c;
        while ((c = in.read()) != -1) {
            bob.append((char) c);
        }
        return bob.toString();
    }
}

Related

  1. readAll(InputStream i, byte b[])
  2. readAll(InputStream in)
  3. readall(InputStream in)
  4. readAll(InputStream in)
  5. readAll(InputStream in)
  6. readAll(InputStream in)
  7. readAll(InputStream in, byte[] buffer, int off, int len)
  8. readall(InputStream in, byte[] buffer, int offset, int len)
  9. readAll(InputStream inputStream)