Java InputStream to Byte Array inputStreamToByteArray(InputStream is)

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

Description

input Stream To Byte Array

License

Open Source License

Declaration

public static byte[] inputStreamToByteArray(InputStream is) throws IOException 

Method Source Code

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

import java.io.*;

public class Main {

    public static byte[] inputStreamToByteArray(InputStream is) throws IOException {
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();

        try {//from w ww  .  j  a v a2 s  .  c  o m
            int ch = -1;

            while ((ch = is.read()) != -1) {
                byteStream.write(ch);
            }

            return byteStream.toByteArray();
        } finally {
            byteStream.close();
        }
    }
}

Related

  1. inputStreamToByteArray(InputStream input, int size)
  2. InputStreamToByteArray(InputStream inputStream)
  3. inputStreamToByteArray(InputStream ins)
  4. inputStreamToByteArray(InputStream is)
  5. inputStreamToByteArray(InputStream is)
  6. inputStreamToByteArray(InputStream is)
  7. inputStreamToByteArray(InputStream is)
  8. inputStreamToByteArray(InputStream stream)
  9. inputStreamToByteArrayOutputStream(final InputStream is)