Java InputStream Read by Charset inputStreamAsString(InputStream stream, Charset cs)

Here you can find the source of inputStreamAsString(InputStream stream, Charset cs)

Description

input Stream As String

License

Open Source License

Declaration

public static String inputStreamAsString(InputStream stream, Charset cs) throws IOException 

Method Source Code


//package com.java2s;
/*//from  w ww  .ja v  a  2  s.  co m
 * TDMX - Trusted Domain Messaging eXchange
 * 
 * Enterprise B2B messaging between separate corporations via interoperable cloud service providers.
 * 
 * Copyright (C) 2014 Peter Klauser (http://tdmx.org)
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
 * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * 
 * This program 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 Affero General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses/.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;

public class Main {
    public static String inputStreamAsString(InputStream stream, Charset cs) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(stream, cs));
        StringBuilder sb = new StringBuilder();
        String line = null;

        while ((line = br.readLine()) != null) {
            sb.append(line).append("\n");
        }

        br.close();
        return sb.toString();
    }
}

Related

  1. getHeaderLen(FileInputStream in, Charset encoding)
  2. getInputCharset()
  3. getStreamAsString(InputStream source, Charset charset)
  4. getText(InputStream stream, Charset charset)
  5. input2String(InputStream input, Charset encoding)
  6. inputStreamToString(final InputStream inputStream, final String charsetName)
  7. inputstreamToString(InputStream input, CharsetDecoder decoder)
  8. inputStreamToString(InputStream inputStream, Charset charset)
  9. inputStreamToString(InputStream inputStream, String charset)