Android InputStream Read readAllBytes(InputStream in)

Here you can find the source of readAllBytes(InputStream in)

Description

read All Bytes

License

Open Source License

Declaration

public static byte[] readAllBytes(InputStream in) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class Main {
    public static byte[] readAllBytes(InputStream in) throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        copyAllBytes(in, out);/*w w  w . ja  v  a 2s. co m*/
        return out.toByteArray();
    }

    public static int copyAllBytes(InputStream in, OutputStream out)
            throws IOException {
        int byteCount = 0;
        byte[] buffer = new byte[4096];
        while (true) {
            int read = in.read(buffer);
            if (read == -1) {
                break;
            }
            out.write(buffer, 0, read);
            byteCount += read;
        }
        return byteCount;
    }
}

Related

  1. readStream(InputStream in)
  2. readStream(InputStream in)
  3. readStream(InputStream in)
  4. readToFile(InputStream in, File localFile)
  5. readAllAndClose(InputStream is)
  6. readAllBytesToOutput(InputStream is, OutputStream output)
  7. readAllNoClose(InputStream is)
  8. readBSInt(InputStream is)
  9. readFully(InputStream inputStream)