Here you can find the source of loadStreamContent(InputStream stream)
Parameter | Description |
---|---|
fileName | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String loadStreamContent(InputStream stream) throws IOException
//package com.java2s; /*/*from w w w .j ava 2s. co m*/ * Copyright (c) 2012-2015 VMware, Inc. 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. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License 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; public class Main { /** * Loads a file into string * * @param fileName * @return String content of the file * @throws IOException */ public static String loadStreamContent(InputStream stream) throws IOException { StringBuilder content = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8")); try { char[] buff = new char[1024]; int i = 0; while ((i = reader.read(buff)) != -1) { content.append(buff, 0, i); } } finally { reader.close(); } return content.toString(); } }