Java InputStream Read Bytes readBytes(InputStream inputStream)

Here you can find the source of readBytes(InputStream inputStream)

Description

read Bytes

License

Open Source License

Declaration

public static byte[] readBytes(InputStream inputStream) throws IOException 

Method Source Code


//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.io.*;

public class Main {
    public static byte[] readBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        copyStream(inputStream, byteOut);
        return byteOut.toByteArray();
    }/*from   ww w .j a va2s.  c  om*/

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

Related

  1. readBytes(InputStream input, int size, byte[] buffer)
  2. readBytes(InputStream inputStream)
  3. readBytes(InputStream inputStream)
  4. readBytes(InputStream inputStream)
  5. readBytes(InputStream inputStream)
  6. readBytes(InputStream inputStream)
  7. readBytes(InputStream inputStream)
  8. readBytes(InputStream inputStream)
  9. readBytes(InputStream inputStream)