Java InputStream to String inputStreamToString(final InputStream is, final int bufferSize)

Here you can find the source of inputStreamToString(final InputStream is, final int bufferSize)

Description

input Stream To String

License

Open Source License

Declaration

public static String inputStreamToString(final InputStream is,
            final int bufferSize) 

Method Source Code

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

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

import java.io.Reader;

import java.io.UnsupportedEncodingException;

public class Main {
    public static String inputStreamToString(final InputStream is,
            final int bufferSize) {
        final char[] buffer = new char[bufferSize];
        final StringBuilder out = new StringBuilder();
        try (Reader in = new InputStreamReader(is, "UTF-8")) {
            for (;;) {
                int rsz = in.read(buffer, 0, buffer.length);
                if (rsz < 0)
                    break;
                out.append(buffer, 0, rsz);
            }/*from   w w w  . ja  v  a2 s  . c  om*/
        } catch (UnsupportedEncodingException ex) {
            return ""; /* ... */
        } catch (IOException ex) {
            return ""; /* ... */
        }
        return out.toString();
    }
}

Related

  1. inputStreamReaderToStringBuilder(InputStreamReader reader, StringBuilder builder)
  2. inputStreamToReaderToString(InputStream in)
  3. inputStreamtoStream(InputStream in)
  4. inputStreamToString(final InputStream in)
  5. inputStreamToString(final InputStream inputStream, final String... optionalCharsetName)
  6. inputStreamToString(final InputStream stream)
  7. inputStreamToString(final InputStream stream, final String charset)
  8. inputStreamToString(InputStream in)
  9. inputStreamToString(InputStream in)