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;
//License from project: Open Source License 

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

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

        ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();

        int bufferSize = 1024;
        byte[] buffer = new byte[bufferSize];

        int len = 0;

        while ((len = inputStream.read(buffer)) != -1) {
            byteBuffer.write(buffer, 0, len);
        }//from  w  w w. ja  v a2  s . c om

        return byteBuffer.toByteArray();
    }
}

Related

  1. readBytes(InputStream input, byte[] data, int capacity)
  2. readBytes(InputStream input, Class type)
  3. readbytes(InputStream input, int n)
  4. readBytes(InputStream input, int size, byte[] buffer)
  5. readBytes(InputStream inputStream)
  6. readBytes(InputStream inputStream)
  7. readBytes(InputStream inputStream)
  8. readBytes(InputStream inputStream)
  9. readBytes(InputStream inputStream)