Java InputStream to Byte Array inputStreamToBytes(InputStream in)

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

Description

Converts an InputStream to a byte[]

License

Open Source License

Declaration

public static byte[] inputStreamToBytes(InputStream in) 

Method Source Code

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

import java.io.ByteArrayOutputStream;

import java.io.InputStream;

public class Main {
    /**/*from  w  w  w  . j av  a2 s . c  o  m*/
     * Converts an InputStream to a byte[]
     * 
     */
    public static byte[] inputStreamToBytes(InputStream in) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            byte[] buffer = new byte[1024];
            int len;
            while ((len = in.read(buffer)) != -1) {
                out.write(buffer, 0, len);
            }
        } catch (Exception e) {
            System.out.println("Error converting InputStream to byte[]: " + e.getMessage());
        }
        return out.toByteArray();
    }
}

Related

  1. inputStreamToByteArray(InputStream is)
  2. inputStreamToByteArray(InputStream stream)
  3. inputStreamToByteArrayOutputStream(final InputStream is)
  4. inputStreamToBytes(final InputStream aInputStream)
  5. inputStreamToBytes(final InputStream ins)
  6. inputStreamToBytes(InputStream in)
  7. inputStreamToBytes(InputStream in)
  8. inputStreamToBytes(InputStream is)
  9. loadByteCode(String name, final InputStream is)