Java Utililty Methods InputStream to String

List of utility methods to do InputStream to String

Description

The list of methods to do InputStream to String are organized into topic(s).

Method

StringinputStream2String(InputStream in)
This method converts an input stream into a string.
try {
    StringBuffer buf = new StringBuffer();
    while (in.available() > 0) {
        int i = in.read();
        buf.append((char) i);
    return buf.toString();
} catch (IOException e) {
...
StringInputStream2String(InputStream in, String encoding)
Input Stream String
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[1024];
int count = -1;
while ((count = in.read(data, 0, 1024)) != -1)
    outStream.write(data, 0, count);
data = null;
return new String(outStream.toByteArray(), encoding);
StringInputStream2String(InputStream in_st, String charset)
Input Stream String
BufferedReader buff = new BufferedReader(new InputStreamReader(in_st, charset));
StringBuffer res = new StringBuffer();
String line = "";
while ((line = buff.readLine()) != null) {
    res.append(line);
return res.toString();
StringinputStream2String(InputStream inputstream)
input Stream String
BufferedReader in = new BufferedReader(new InputStreamReader(inputstream));
StringBuffer buffer = new StringBuffer();
String line = "";
try {
    while ((line = in.readLine()) != null) {
        buffer.append(line);
} catch (Exception e) {
...
StringinputStream2String(InputStream inStream)
input Stream String
return new String(inputStream2byte(inStream));
StringinputStream2String(InputStream is)
input Stream String
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = -1;
try {
    while ((i = is.read()) != -1) {
        baos.write(i);
} catch (IOException e) {
    e.printStackTrace();
...
StringinputStream2String(InputStream is)
input Stream String
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = -1;
try {
    while ((i = is.read()) != -1) {
        baos.write(i);
} catch (IOException e) {
    e.printStackTrace();
...
StringinputStream2String(InputStream is)
input Stream String
BufferedReader in = new BufferedReader(new InputStreamReader(is));
StringBuffer buffer = new StringBuffer();
String line = "";
try {
    while ((line = in.readLine()) != null) {
        buffer.append(line);
} catch (IOException e) {
...
StringinputStream2String(InputStream is)
input Stream String
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = -1;
while ((i = is.read()) != -1) {
    baos.write(i);
byte[] lens = baos.toByteArray();
String result = new String(lens, "UTF-8");
return result;
...
StringinputStream2String(InputStream source)
Read String from InputStream.
StringWriter writer = new StringWriter();
BufferedReader reader = new BufferedReader(new InputStreamReader(source));
try {
    char[] buffer = new char[BUFFER_SIZE];
    int charactersRead = reader.read(buffer, 0, buffer.length);
    while (charactersRead != -1) {
        writer.write(buffer, 0, charactersRead);
        charactersRead = reader.read(buffer, 0, buffer.length);
...