Here you can find the source of getStreamAsString(final InputStream stream)
Parameter | Description |
---|---|
stream | The input stream |
Parameter | Description |
---|---|
IOException | Thrown if the resource cannot be located. |
public static String getStreamAsString(final InputStream stream) throws IOException
//package com.java2s; /*/*w w w . ja v a2 s.c o m*/ * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at license/ESCIDOC.LICENSE * or http://www.escidoc.org/license. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at license/ESCIDOC.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { /** * Gets a stream as String. * * @param stream The input stream * @return The resource as String. * @throws IOException Thrown if the resource cannot be located. */ public static String getStreamAsString(final InputStream stream) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(stream, "UTF-8")); String line = null; StringBuilder result = new StringBuilder(); while ((line = br.readLine()) != null) { result.append(line); result.append("\n"); } stream.close(); return result.toString(); } }