Java InputStream to String InputStreamToString(InputStream inputStream)

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

Description

Method converts a given input stream to a string.

License

Open Source License

Parameter

Parameter Description
inputStream InputStream to be read.

Exception

Parameter Description
IOException an exception

Return

The string version of the input stream.

Declaration

public static String InputStreamToString(InputStream inputStream) throws IOException 

Method Source Code

//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();
    }
}

Related

  1. InputStreamTOString(InputStream in, String encoding)
  2. inputStreamToString(InputStream input)
  3. InputStreamToString(InputStream input_stream)
  4. inputStreamToString(InputStream inputStream)
  5. InputStreamToString(InputStream inputStream)
  6. inputStreamToString(InputStream inputStream)
  7. inputStreamToString(InputStream inputStream)
  8. inputStreamToString(InputStream inputStream)
  9. inputStreamToString(InputStream inputStream)