Java InputStream to String getInputStreamContent(InputStream inputStream)

Here you can find the source of getInputStreamContent(InputStream inputStream)

Description

Get InputStream to String

License

Open Source License

Parameter

Parameter Description
inputStream a parameter

Exception

Parameter Description
IOException an exception

Return

String input value as string

Declaration

public static String getInputStreamContent(InputStream inputStream) throws IOException 

Method Source Code


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

import java.io.BufferedReader;

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

public class Main {
    private static final char NL = '\n';

    /**//from www  . j av a 2  s  . c o m
     * Get InputStream to String
     * 
     * @param inputStream
     * @return String input value as string
     * @throws IOException
     */
    public static String getInputStreamContent(InputStream inputStream) throws IOException {
        BufferedReader bufferReader = new BufferedReader(new InputStreamReader(inputStream));
        StringBuffer result = new StringBuffer();
        String line;
        while ((line = bufferReader.readLine()) != null) {
            result.append(line).append(NL);
        }
        bufferReader.close();
        return result.toString();
    }
}

Related

  1. asArrayString(InputStream response)
  2. getInputStreamAsString(final InputStream is, final String encoding)
  3. getInputStreamAsString(InputStream inStream)
  4. getInputStreamAsString(InputStream stream)
  5. getInputStreamContent(InputStream i, String encoding)
  6. getInputStreamContents(InputStream inputStream)
  7. getInputStreamContents(InputStream inputStream)
  8. getStreamAsString(final InputStream stream)
  9. getStreamAsString(InputStream input, String charset)