Android InputStream to String Convert InputStreamToString(InputStream stream)

Here you can find the source of InputStreamToString(InputStream stream)

Description

Input Stream To String

License

Open Source License

Declaration

public static String InputStreamToString(InputStream stream)
            throws IOException 

Method Source Code

//package com.java2s;
/**//  www  .j a  v a  2s. com
 *     Copyright (C) 2009 Anders Aagaard <aagaande@gmail.com>
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    public static String InputStreamToString(InputStream stream)
            throws IOException {
        //long perfSTART = System.currentTimeMillis();

        final InputStreamReader input = new InputStreamReader(stream,
                "UTF-8");
        final char[] buffer = new char[8192];
        final StringBuilder output = new StringBuilder(8192);
        try {
            for (int read = input.read(buffer, 0, buffer.length); read != -1; read = input
                    .read(buffer, 0, buffer.length)) {
                output.append(buffer, 0, read);
            }
        } catch (IOException e) {
        }
        //Log.i(TAG,"PERF : Downloading web request took " + ((System.currentTimeMillis() - perfSTART)) + "ms");
        return output.toString();
    }
}

Related

  1. toString(InputStream is)
  2. toStringBuffer(InputStream is)
  3. inputStream2String(InputStream in)
  4. inputStreamToString(InputStream in)
  5. inputStreamToString(InputStream is)
  6. convertInputStreamToString(InputStream inputStream)
  7. convertStreamToString(InputStream inputStream)
  8. convertStreamToString(InputStream inputStream)
  9. convertStreamToString(InputStream is)