Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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;

import android.util.Log;

public class Main {
    public static String convertStreamToString(InputStream is) {
        if (is != null) {
            StringBuilder sb = new StringBuilder();
            String line;

            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                while ((line = reader.readLine()) != null) {
                    sb.append(line).append("\n");
                }
            } catch (IOException e) {
                Log.e(e.getClass().getName() + " convertStreamToString", e.getMessage(), e);
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    Log.e(e.getClass().getName() + " convertStreamToString", e.getMessage(), e);
                }
            }
            return sb.toString();
        } else {
            return "";
        }
    }
}