Here you can find the source of InputStreamToString(InputStream inputStream)
Parameter | Description |
---|---|
inputStream | InputStream to be read. |
Parameter | Description |
---|---|
IOException | an exception |
public static String InputStreamToString(InputStream inputStream) throws IOException
//package com.java2s; /*/*from ww w . ja v a2 s . c o m*/ * This file is part of Yet Another jDownloader. jDownloader is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. jDownloader is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with jDownloader. If not, see <http://www.gnu.org/licenses/>. */ import java.io.IOException; import java.io.InputStream; public class Main { /** * Method converts a given input stream to a string. * @param inputStream InputStream to be read. * @return The string version of the input stream. * @throws IOException */ public static String InputStreamToString(InputStream inputStream) throws IOException { StringBuilder returnStringBuilder = null; if (inputStream != null) { returnStringBuilder = new StringBuilder(); int readByteInt; while ((readByteInt = inputStream.read()) != -1) { returnStringBuilder.append((char) readByteInt); } } return returnStringBuilder == null ? null : returnStringBuilder.toString(); } }