Android InputStream to String Convert inputStream2String(InputStream is)

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

Description

convert inputstream to string

Parameter

Parameter Description
is a parameter

Declaration

public static String inputStream2String(InputStream is) 

Method Source Code

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

public class Main {
    /**/*from w  w  w .  java  2 s.c o  m*/
     * convert inputstream to string
     * 
     * @param is
     * @return
     */
    public static String inputStream2String(InputStream is) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] data = new byte[1024];
        int len = 0;
        String result = "";

        if (is != null) {
            try {
                while ((len = is.read(data)) != -1) {
                    baos.write(data, 0, len);
                }
                result = new String(baos.toByteArray(), "UTF8");
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }
        return null;
    }
}

Related

  1. convertInputStreamToString(InputStream inputStream)
  2. inputStream2String(InputStream is)
  3. readStreamAsString(InputStream is)
  4. readStringFromStream(InputStream is)
  5. getString(InputStream is)
  6. inputStream2String(InputStream in)
  7. stream2String(InputStream is, int maxLength)
  8. fromStream(InputStream stream)
  9. toConvertString(InputStream is)