Java InputStream to String getStreamAsString(InputStream stream)

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

Description

get Stream As String

License

Open Source License

Declaration

public static String getStreamAsString(InputStream stream) throws IOException 

Method Source Code


//package com.java2s;
/*/*from w  w  w  . ja  va 2s .co  m*/
 * Copyright (c) 2013, Miguel Martins
 * Use is subject to license terms.
 *
 * This source code file is provided under the MIT License. Full licensing
 * terms should be available in the form of text files. The standard source code
 * distribution provides a LICENSE.txt file which can be consulted for licensing
 * details.
 */

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

public class Main {
    public static String getStreamAsString(InputStream stream) throws IOException {
        String output = "";
        byte[] buffer = new byte[4096];
        while (stream.read(buffer) > 0) {
            output = output + new String(buffer);
        }
        return output;
    }
}

Related

  1. getInputStreamContents(InputStream inputStream)
  2. getInputStreamContents(InputStream inputStream)
  3. getStreamAsString(final InputStream stream)
  4. getStreamAsString(InputStream input, String charset)
  5. getStreamAsString(InputStream is, String encoding)
  6. getStreamAsString(InputStream stream, String charset)
  7. getStreamContent(InputStream is)
  8. getStreamContent(InputStream stream, int bufferSize)
  9. getStreamContentAsString(InputStream is)