Java InputStream Read Bytes readBytes(InputStream is)

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

Description

read Bytes

License

Open Source License

Declaration

public static byte[] readBytes(InputStream is) 

Method Source Code


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

import java.io.BufferedInputStream;

import java.io.ByteArrayOutputStream;

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

public class Main {
    public static byte[] readBytes(InputStream is) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try (InputStream bis = new BufferedInputStream(is)) {
            int b;
            while ((b = bis.read()) >= 0) {
                bos.write(b);/*  w  w w .  j av a  2 s .c  om*/
            }
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
        return bos.toByteArray();
    }
}

Related

  1. readBytes(InputStream inputStream, int numberOfBytes)
  2. readBytes(InputStream inputStream, int numberOfBytes)
  3. readBytes(InputStream ins, byte[] buf, int size)
  4. readBytes(InputStream is)
  5. readBytes(InputStream is)
  6. readBytes(InputStream is)
  7. readBytes(InputStream is)