Here you can find the source of inputStreamToString(InputStream input)
Parameter | Description |
---|---|
input | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String inputStreamToString(InputStream input) throws IOException
//package com.java2s; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringWriter; public class Main { /** Deprecated/* w w w. j a v a 2 s. c o m*/ * @param input * @return String form of input stream * @throws IOException */ public static String inputStreamToString(InputStream input) throws IOException { if (input != null) { StringWriter writer = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(input)); int n; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } } finally { input.close(); } return writer.toString().trim(); } else { return ""; } } }