Java InputStream to String inputStream2String(InputStream source)

Here you can find the source of inputStream2String(InputStream source)

Description

Read String from InputStream.

License

LGPL

Declaration

public static String inputStream2String(InputStream source) throws IOException 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.io.*;

public class Main {
    private static final int BUFFER_SIZE = 16384;

    /** Read String from InputStream. */
    public static String inputStream2String(InputStream source) throws IOException {
        StringWriter writer = new StringWriter();
        BufferedReader reader = new BufferedReader(new InputStreamReader(source));
        try {//w  w  w .  ja v a  2 s .  co  m
            char[] buffer = new char[BUFFER_SIZE];
            int charactersRead = reader.read(buffer, 0, buffer.length);
            while (charactersRead != -1) {
                writer.write(buffer, 0, charactersRead);
                charactersRead = reader.read(buffer, 0, buffer.length);
            }
        } finally {
            reader.close();
        }
        return writer.toString();
    }
}

Related

  1. inputStream2String(InputStream inStream)
  2. inputStream2String(InputStream is)
  3. inputStream2String(InputStream is)
  4. inputStream2String(InputStream is)
  5. inputStream2String(InputStream is)
  6. inputstream_to_string(InputStream in)
  7. inputStreamAsString(InputStream is)
  8. inputStreamReaderToStringBuilder(InputStreamReader reader, StringBuilder builder)
  9. inputStreamToReaderToString(InputStream in)