Java BufferedReader Read loadStreamContent(InputStream stream)

Here you can find the source of loadStreamContent(InputStream stream)

Description

Loads a file into string

License

Open Source License

Parameter

Parameter Description
fileName a parameter

Exception

Parameter Description
IOException an exception

Return

String content of the file

Declaration

public static String loadStreamContent(InputStream stream) throws IOException 

Method Source Code


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

Related

  1. loadSentences(InputStream stream, List jsonSentences)
  2. loadSimpleTextFile(File file, int bufferSize)
  3. loadSqlFile(String path)
  4. loadSQLFromFile(String fileName)
  5. loadStream(InputStream is)
  6. loadSystemClassPath()
  7. loadTableList(List list, String fileName)
  8. loadTemplate(final String resource)
  9. loadTemplate(String templateUrl)