Java InputStream to Byte Array inputStreamToByte(InputStream in)

Here you can find the source of inputStreamToByte(InputStream in)

Description

input stream to byte

License

Open Source License

Parameter

Parameter Description
in InputStream

Exception

Parameter Description
IOException an exception

Return

byte[]

Declaration

public static byte[] inputStreamToByte(InputStream in)
        throws IOException 

Method Source Code

//package com.java2s;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static final int BUFFER_SIZE = 8192;

    /**/*from  w ww. j  av  a 2s .  co m*/
     * input stream to byte
     * @param in InputStream
     * @return byte[]
     * @throws IOException
     */
    public static byte[] inputStreamToByte(InputStream in)
            throws IOException {

        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] data = new byte[BUFFER_SIZE];
        int count = -1;
        while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) {
            outStream.write(data, 0, count);
        }

        data = null;
        return outStream.toByteArray();
    }
}

Related

  1. getStreamToBytes(InputStream stream)
  2. inputStream2ByteArray(InputStream input)
  3. inputStream2ByteArray(InputStream is)
  4. inputStreamAsBytes(InputStream stream)
  5. inputStreamToArray(InputStream is)
  6. InputStreamTOByte(InputStream in)
  7. inputStreamToByte(InputStream is)
  8. inputStreamToByteArray(final InputStream is, final int bufferSize)
  9. inputStreamToByteArray(InputStream in)