Java InputStream Read by Charset toString(final InputStream input, final Charset encoding)

Here you can find the source of toString(final InputStream input, final Charset encoding)

Description

to String

License

Open Source License

Declaration

public static String toString(final InputStream input, final Charset encoding) throws IOException 

Method Source Code

//package com.java2s;

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

import java.io.Reader;

import java.nio.charset.Charset;

public class Main {
    public static String toString(final InputStream input) throws IOException {
        return toString(input, Charset.defaultCharset());
    }//from w w  w  .  jav  a2s .c  o  m

    public static String toString(final InputStream input, final Charset encoding) throws IOException {
        return toString(new InputStreamReader(input, encoding));
    }

    public static String toString(final Reader input) throws IOException {
        final StringBuilder sb = new StringBuilder();
        final char[] buffer = new char[4096];
        for (int charsRead; -1 != (charsRead = input.read(buffer));) {
            sb.append(buffer, 0, charsRead);
        }
        return sb.toString();
    }
}

Related

  1. streamToString(InputStream inputStream, Charset encoding)
  2. stringFromStream(InputStream in, Charset cs)
  3. toInputStream(final String string, final Charset charset)
  4. toInputStream(String input, Charset charset)
  5. toInputStream(String input, Charset cs)
  6. toString(InputStream in, Charset charset)
  7. toString(InputStream in, Charset charset)
  8. toString(InputStream in, Charset charset)
  9. toString(InputStream in, Charset charset)