Java InputStream to String InputStreamTOString(InputStream in, String encoding)

Here you can find the source of InputStreamTOString(InputStream in, String encoding)

Description

Input Stream TO String

License

Apache License

Declaration

public static String InputStreamTOString(InputStream in, String encoding) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {

    public static String InputStreamTOString(InputStream in, String encoding) throws IOException {

        return new String(InputStreamTOByte(in), encoding);

    }// ww  w .j a va2s . c o  m

    public static byte[] InputStreamTOByte(InputStream in) throws IOException {

        int BUFFER_SIZE = 4096;
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] data = new byte[BUFFER_SIZE];
        int count = -1;

        while ((count = in.read(data, 0, BUFFER_SIZE)) != -1)
            outStream.write(data, 0, count);

        data = null;
        byte[] outByte = outStream.toByteArray();
        outStream.close();

        return outByte;
    }
}

Related

  1. inputStreamToString(InputStream in)
  2. InputStreamTOString(InputStream in)
  3. InputStreamToString(InputStream in)
  4. InputStreamTOString(InputStream in)
  5. InputStreamToString(InputStream in, String charset)
  6. inputStreamToString(InputStream input)
  7. InputStreamToString(InputStream input_stream)
  8. inputStreamToString(InputStream inputStream)
  9. InputStreamToString(InputStream inputStream)