Java InputStream Read getFileContent(InputStream is)

Here you can find the source of getFileContent(InputStream is)

Description

There is a much cleaner implementation of doing this, but good enough since it is only used for testing

License

BSD License

Declaration

public static String getFileContent(InputStream is) throws IOException 

Method Source Code


//package com.java2s;
/*L/*from w w w  .j a v  a  2 s  .  c  o  m*/
 * Copyright Oracle Inc, SAIC-F.
 *
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/cadsr-bulk-loader/LICENSE.txt for details.
 */

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    /**
     * There is a much cleaner implementation of doing this, but good
     * enough since it is only used for testing
     */
    public static String getFileContent(InputStream is) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line = null;
        StringBuffer buff = new StringBuffer();

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

        return buff.toString();
    }
}

Related

  1. getFileContent(InputStream in)
  2. getFileContent(InputStream inputStream)
  3. getFileContent(InputStream stream)
  4. getInputStream(Class clazz)
  5. getInputStream(Class ownerClass, String subName, String extension)
  6. getInputstream(File compressedFile)