Java InputStream to Byte Array getBytes(InputStream inputStream)

Here you can find the source of getBytes(InputStream inputStream)

Description

get Bytes

License

Apache License

Declaration

public static byte[] getBytes(InputStream inputStream) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    private static final int BUFFER_SIZE = 1024;

    public static byte[] getBytes(InputStream inputStream) throws IOException {
        assert null != inputStream;
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();

        int numberRead;
        byte[] data = new byte[BUFFER_SIZE];

        while ((numberRead = inputStream.read(data, 0, data.length)) != -1) {
            buffer.write(data, 0, numberRead);
        }/*from www .j a  v a2s. c o  m*/

        buffer.flush();

        return buffer.toByteArray();
    }
}

Related

  1. getBytes(InputStream input)
  2. getBytes(InputStream input)
  3. getBytes(InputStream input)
  4. getBytes(InputStream inputStream)
  5. getBytes(InputStream inputStream)
  6. getBytes(InputStream inputStream)
  7. getBytes(InputStream is)
  8. getBytes(InputStream is)
  9. getBytes(InputStream is)