Java InputStream Read All readAll(InputStream in)

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

Description

read All

License

Open Source License

Declaration

public static String readAll(InputStream in) throws IOException 

Method Source Code

//package com.java2s;
/*//from  w ww .j av  a2 s.c  o  m
 * Copyright (C) ${year} Omry Yadan <${email}>
 * All rights reserved.
 *
 * See https://github.com/omry/banana/blob/master/BSD-LICENSE for licensing information
 */

import java.io.*;

import java.util.*;

public class Main {
    public static String readAll(InputStream in) throws IOException {
        StringBuffer b = new StringBuffer();
        int c;
        while ((c = in.read()) != -1) {
            b.append((char) c);
        }
        return b.toString();
    }

    public static String toString(Collection<String> list) {
        return toString(list.toArray(new String[list.size()]));
    }

    public static String toString(Object array[]) {
        return toString(array, ",");
    }

    public static String toString(int array[]) {
        return toString(array, ",");
    }

    public static String toString(long array[]) {
        return toString(array, ",");
    }

    public static String toString(double[] array) {
        return toString(array, ",");
    }

    public static String toString(Object array[], String sep) {
        return toString(array, sep, 0, array.length);
    }

    public static String toString(Object array[], String sep, int start, int end) {
        StringBuffer sb = new StringBuffer();
        for (int i = start; i < end; i++) {
            if (i > start)
                sb.append(sep);
            sb.append(array[i]);
        }
        return sb.toString();
    }

    public static String toString(long array[], String sep) {
        return toString(array, sep, 0, array.length);
    }

    public static String toString(double array[], String sep) {
        return toString(array, sep, 0, array.length);
    }

    public static String toString(int array[], String sep) {
        return toString(array, sep, 0, array.length);
    }

    public static String toString(double array[], String sep, int start, int end) {
        StringBuffer sb = new StringBuffer();
        for (int i = start; i < end; i++) {
            if (i > 0)
                sb.append(sep);
            sb.append(array[i]);
        }
        return sb.toString();
    }

    public static String toString(long array[], String sep, int start, int end) {
        StringBuffer sb = new StringBuffer();
        for (int i = start; i < end; i++) {
            if (i > 0)
                sb.append(sep);
            sb.append(array[i]);
        }
        return sb.toString();
    }

    public static String toString(int array[], String sep, int start, int end) {
        StringBuffer sb = new StringBuffer();
        for (int i = start; i < end; i++) {
            if (i > 0)
                sb.append(sep);
            sb.append(array[i]);
        }
        return sb.toString();
    }
}

Related

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