Android Utililty Methods InputStream Read

List of utility methods to do InputStream Read

Description

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

Method

StringreadStream(InputStream in)
read Stream
StringBuilder sb = new StringBuilder();
BufferedReader r = new BufferedReader(new InputStreamReader(in),
        1024);
for (String line = r.readLine(); line != null; line = r.readLine()) {
    sb.append(line);
in.close();
return sb.toString();
...
voidreadToFile(InputStream in, File localFile)
Reads the whole InputStream content into a local file
OutputStream output = null;
try {
    output = new FileOutputStream(localFile);
    in = new BufferedInputStream(in);
    byte data[] = new byte[1024];
    int count;
    while ((count = in.read(data)) != -1) {
        output.write(data, 0, count);
...
byte[]readAllAndClose(InputStream is)
read All And Close
try {
    return readAllNoClose(is);
} finally {
    is.close();
byte[]readAllBytes(InputStream in)
read All Bytes
ByteArrayOutputStream out = new ByteArrayOutputStream();
copyAllBytes(in, out);
return out.toByteArray();
intreadAllBytesToOutput(InputStream is, OutputStream output)
read All Bytes To Output
byte[] tempBuffer = new byte[TEMP_BUFFER_DEFAULT_LENGTH];
int readed;
int totalRead = 0;
while (true) {
    readed = is.read(tempBuffer, 0, TEMP_BUFFER_DEFAULT_LENGTH);
    if (readed < 0) {
        break;
    totalRead += readed;
    if (readed != 0) {
        output.write(tempBuffer, 0, readed);
        output.flush();
return totalRead;
byte[]readAllNoClose(InputStream is)
read All No Close
ByteArrayOutputStream ret = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
for (;;) {
    int bytesRead = is.read(buf);
    if (bytesRead <= 0) {
        break;
    ret.write(buf, 0, bytesRead);
...
intreadBSInt(InputStream is)
read BS Int
int i1 = is.read();
int i2 = is.read();
int i3 = is.read();
int i4 = is.read();
return i1 + (i2 << 8) + (i3 << 16) + (i4 << 24);
byte[]readFully(InputStream inputStream)
read Fully
ByteArrayOutputStream os = new ByteArrayOutputStream();
int byteCount;
byte[] buffer = new byte[1024];
while ((byteCount = inputStream.read(buffer)) != -1) {
    os.write(buffer, 0, byteCount);
return os.toByteArray();
byte[]readFullyAndClose(InputStream is)
Reads all the bytes from the given input stream.
try {
    byte[] buffer = new byte[1024];
    int count = is.read(buffer);
    int nextByte = is.read();
    if (nextByte == -1) {
        return Arrays.copyOf(buffer, count);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(
...
byte[]readInputStream(InputStream inStream)
read Input Stream
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = inStream.read(buffer)) != -1) {
    outStream.write(buffer, 0, len);
byte[] data = outStream.toByteArray();
outStream.close();
...