Android InputStream to String Convert inStream2Str(InputStream inputStream, String encode)

Here you can find the source of inStream2Str(InputStream inputStream, String encode)

Description

in Stream Str

License

Open Source License

Declaration

public static String inStream2Str(InputStream inputStream, String encode) 

Method Source Code

//package com.java2s;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;

public class Main {

    public static String inStream2Str(InputStream inputStream, String encode) {

        String result = null;//from   ww w  .  j  a va 2 s . co m

        if (inputStream != null) {

            try {
                BufferedInputStream bis = new BufferedInputStream(
                        inputStream);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                int position = 0;
                while ((position = bis.read()) != -1) {
                    baos.write((byte) position);
                }
                if (encode == null) {
                    result = baos.toString();
                } else {
                    result = baos.toString(encode);
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        return result;
    }
}

Related

  1. converStreamToString(InputStream is)
  2. inputStreamToString(InputStream inputStream)
  3. streamToString(InputStream is)
  4. slurp(InputStream in)
  5. convertStreamToString(InputStream is)
  6. readIt(InputStream stream)
  7. inputStream2String(InputStream inputStream)
  8. InputStreamTOString(InputStream in)
  9. InputStreamTOString(InputStream in)