Java InputStream to String inputStream2String(InputStream inputstream)

Here you can find the source of inputStream2String(InputStream inputstream)

Description

input Stream String

License

Open Source License

Declaration

public static String inputStream2String(InputStream inputstream) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static String inputStream2String(InputStream inputstream) {
        BufferedReader in = new BufferedReader(new InputStreamReader(inputstream));
        StringBuffer buffer = new StringBuffer();
        String line = "";
        try {/* w  ww .  jav a 2  s  . c  o  m*/
            while ((line = in.readLine()) != null) {
                buffer.append(line);
            }
        } catch (Exception e) {
            return null;
        } finally {
            safelyCloseInputStream(inputstream);
        }

        return buffer.toString();
    }

    public static void safelyCloseInputStream(InputStream is) {
        try {
            if (is != null) {
                is.close();
                is = null;
            }

        } catch (IOException e) {
        }
    }
}

Related

  1. inputStream2String(InputStream in)
  2. inputStream2String(InputStream in)
  3. inputStream2String(InputStream in)
  4. InputStream2String(InputStream in, String encoding)
  5. InputStream2String(InputStream in_st, String charset)
  6. inputStream2String(InputStream inStream)
  7. inputStream2String(InputStream is)
  8. inputStream2String(InputStream is)
  9. inputStream2String(InputStream is)