Java InputStream Read Bytes readBytes(InputStream is)

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

Description

read Bytes

License

Apache License

Declaration

public static byte[] readBytes(InputStream is) 

Method Source Code


//package com.java2s;
//License from project: Apache 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) {
        BufferedInputStream bufin = new BufferedInputStream(is);
        int buffSize = 1024;
        ByteArrayOutputStream out = new ByteArrayOutputStream(buffSize);
        byte[] temp = new byte[buffSize];
        int size = 0;
        try {/*from  www . jav a 2 s  .c o  m*/
            while ((size = bufin.read(temp)) != -1) {
                out.write(temp, 0, size);
            }
            bufin.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out.toByteArray();
    }
}

Related

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