Here you can find the source of convertStreamToString(final InputStream is, final Charset charset)
Parameter | Description |
---|---|
is | an input stream |
Parameter | Description |
---|---|
IOException | upon a failure reading the input stream |
public static String convertStreamToString(final InputStream is, final Charset charset) throws IOException
//package com.java2s; /*//from w w w . j a va 2 s .c o m * Copyright 2010-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.Charset; public class Main { /** * Converts an input stream into a string value. * * @param is an input stream * @return a string containing the content of the input stream * @throws IOException upon a failure reading the input stream */ public static String convertStreamToString(final InputStream is, final Charset charset) throws IOException { final BufferedReader br = new BufferedReader(new InputStreamReader(is, charset)); final StringBuilder sb = new StringBuilder(); String line = null; while ((line = br.readLine()) != null) { sb.append(line + "\n"); } br.close(); return sb.toString(); } }