Android InputStream to String Convert inStream2String(InputStream is)

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

Description

in Stream String

Declaration

public static String inStream2String(InputStream is) throws Exception 

Method Source Code

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

import java.io.InputStream;

import android.util.Log;

public class Main {
    private static final String TAG = "StringUtil";

    public static String inStream2String(InputStream is) throws Exception {
        ByteArrayOutputStream baos = null;
        try {/*from   w  ww.j  a v  a2  s .  c om*/
            baos = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            int len = -1;
            while ((len = is.read(buf)) != -1) {
                baos.write(buf, 0, len);
            }
            return new String(baos.toByteArray());
        } catch (Exception e) {
            Log.e(TAG, e.getMessage(), e);
            return null;
        } finally {
            if (baos != null) {
                try {
                    baos.close();
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }
        }

    }
}

Related

  1. stream2String(InputStream is, int maxLength)
  2. fromStream(InputStream stream)
  3. toConvertString(InputStream is)
  4. inStream2String(InputStream is)
  5. inputStream2String(InputStream is)
  6. fromStream(InputStream inputStream)
  7. parseString(InputStream is)
  8. convertStreamToString(InputStream is)
  9. readToString(final InputStream inputStream)