Java InputStream Read Bytes readBytes(InputStream inputStream)

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

Description

Reads all bytes from given InputStream.

License

Apache License

Parameter

Parameter Description
inputStream The <code>InputStream</code> to be read.

Exception

Parameter Description
IOException In case of exception during reading of <code>InputStream</code>.

Return

All bytes read from InpuStream.

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    /**// w  w  w.  ja va2s.  co m
     * Reads all bytes from given <code>InputStream</code>. This method does not close underlying
     * <code>InputStream</code> and end of proccess.
     *
     * @param inputStream The <code>InputStream</code> to be read.
     *
     * @return All bytes read from <code>InpuStream</code>.
     * @throws IOException In case of exception during reading of <code>InputStream</code>.
     */
    public static byte[] readBytes(InputStream inputStream) throws IOException {
        ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
        byte[] buff = new byte[1024];
        int r = 0;
        while ((r = inputStream.read(buff)) >= 0) {
            arrayOutputStream.write(buff, 0, r);
        }
        return arrayOutputStream.toByteArray();
    }
}

Related

  1. readBytes(InputStream inputStream)
  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, boolean close)