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

StringinputStreamToString(InputStream in)
input Stream To String
Scanner scanner = new Scanner(in).useDelimiter("\\A");
return scanner.next();
StringinputStreamToString(InputStream in)
Reads the contents of an InputStream to a String .
StringBuffer out = new StringBuffer();
byte[] b = new byte[4096];
for (int n; (n = in.read(b)) != -1;) {
    out.append(new String(b, 0, n));
return out.toString();
StringinputStreamToString(InputStream in)
Reads an InputStream into a String
return inputStreamToString(in, "UTF-8");
StringinputStreamToString(InputStream in)
read a String from an InputStream object.
BufferedReader br = new BufferedReader(new InputStreamReader(in));
StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = br.readLine()) != null) {
    buffer.append(line);
return buffer.toString();
StringinputStreamToString(InputStream in)
input Stream To String
StringBuffer out = new StringBuffer();
byte[] b = new byte[8192];
try {
    for (int n; (n = in.read(b)) != -1;) {
        out.append(new String(b, 0, n));
} catch (Exception e) {
    LOG.severe(e.getMessage());
...
StringInputStreamTOString(InputStream in)
Input Stream TO String
return InputStreamTOString(in, "ISO-8859-1");
StringInputStreamToString(InputStream in)
Input Stream To String
String result = null;
ByteArrayOutputStream outStream = null;
if (in != null) {
    try {
        outStream = new ByteArrayOutputStream();
        byte[] data = new byte[BUFFER_SIZE];
        int count = -1;
        while ((count = in.read(data, 0, BUFFER_SIZE)) != -1)
...
StringInputStreamTOString(InputStream in)
Input Stream TO String
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] data = new byte[BUFFER_SIZE];
String string = null;
int count = 0;
try {
    while ((count = in.read(data, 0, BUFFER_SIZE)) != -1)
        outStream.write(data, 0, count);
} catch (IOException e) {
...
StringInputStreamToString(InputStream in, String charset)
Input Stream To String
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] data = new byte[BUFFER_SIZE];
String string = null;
int count = 0;
while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
    byteArrayOutputStream.write(data, 0, count);
string = new String(byteArrayOutputStream.toByteArray(), charset);
...
StringInputStreamTOString(InputStream in, String encoding)
Input Stream TO String
return new String(InputStreamTOByte(in), encoding);