Java InputStream to String inputStreamToString(InputStream is)

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

Description

input Stream To String

License

Open Source License

Declaration

public static String inputStreamToString(InputStream is) throws IOException 

Method Source Code


//package com.java2s;
/*//from w w w  . j a va  2  s. co m
 * {{{ header & license
 * GeneralUtil.java
 * Copyright (c) 2004, 2005 Patrick Wright
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * }}}
 */

import java.io.*;

public class Main {
    public static String inputStreamToString(InputStream is) throws IOException {
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        StringWriter sw = new StringWriter();
        char c[] = new char[1024];
        while (true) {
            int n = br.read(c, 0, c.length);
            if (n < 0)
                break;
            sw.write(c, 0, n);
        }
        isr.close();
        return sw.toString();
    }
}

Related

  1. inputStreamToString(InputStream inputStream)
  2. inputStreamToString(InputStream inputStream)
  3. inputStreamToString(InputStream inputStream, String charsetName)
  4. inputStreamToString(InputStream is)
  5. inputStreamToString(InputStream is)
  6. inputStreamToString(InputStream is)
  7. inputStreamToString(InputStream is)
  8. inputStreamToString(InputStream is)
  9. inputStreamToString(InputStream s)