Java InputStream to String inputStreamtoStream(InputStream in)

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

Description

input Streamto Stream

License

Creative Commons License

Declaration

private static String inputStreamtoStream(InputStream in) throws UnsupportedEncodingException, IOException 

Method Source Code


//package com.java2s;
/*//from   w w w . j  a  v a2s . c o m
 * Creative Commons License: Attribution-ShareAlike 4.0 International
 * https://creativecommons.org/licenses/by-sa/4.0/legalcode
 */

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

public class Main {
    private static String inputStreamtoStream(InputStream in) throws UnsupportedEncodingException, IOException {

        StringBuilder sb = new StringBuilder();

        InputStreamReader is = new InputStreamReader(in, "UTF-8");
        BufferedReader br = new BufferedReader(is);
        String read = br.readLine();

        while (read != null) {
            sb.append(read);
            read = br.readLine();
        }

        return sb.toString();
    }
}

Related

  1. inputStream2String(InputStream source)
  2. inputstream_to_string(InputStream in)
  3. inputStreamAsString(InputStream is)
  4. inputStreamReaderToStringBuilder(InputStreamReader reader, StringBuilder builder)
  5. inputStreamToReaderToString(InputStream in)
  6. inputStreamToString(final InputStream in)
  7. inputStreamToString(final InputStream inputStream, final String... optionalCharsetName)
  8. inputStreamToString(final InputStream is, final int bufferSize)
  9. inputStreamToString(final InputStream stream)