Here you can find the source of streamToString(InputStream is)
Parameter | Description |
---|---|
is | InputStream opened stream from which to read the characters |
Parameter | Description |
---|---|
IOException | an exception |
public static String streamToString(InputStream is) throws IOException
//package com.java2s; import java.io.InputStream; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { /**// www .j av a2 s. c om * Reads a {@link InputStream} into a {@link String} * @param is {@link InputStream} opened stream from which to read the characters * @return {@link String} the read data * @throws IOException */ public static String streamToString(InputStream is) throws IOException { if (is != null) { StringBuilder sb = new StringBuilder(); String line; try { InputStreamReader inputStreamReader = new InputStreamReader( is, "utf-8"); BufferedReader reader = new BufferedReader( inputStreamReader); while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } inputStreamReader = null; reader = null; } finally { is.close(); } String s = sb.toString(); sb = null; return s; } else { return ""; } } }