Java InputStream to Byte Array inputStream2ByteArray(InputStream is)

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

Description

input Stream Byte Array

License

Mozilla Public License

Declaration

public static ByteArrayOutputStream inputStream2ByteArray(InputStream is) throws IOException 

Method Source Code

//package com.java2s;
/**// w  w  w  . ja va  2 s.c  o  m
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * Copyright 2015 Chiori-chan. All Right Reserved.
 * 
 * @author Chiori Greene
 * @email chiorigreene@gmail.com
 */

import java.io.ByteArrayOutputStream;

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

public class Main {
    public static ByteArrayOutputStream inputStream2ByteArray(InputStream is) throws IOException {
        int nRead;
        byte[] data = new byte[16384];
        ByteArrayOutputStream bs = new ByteArrayOutputStream();

        while ((nRead = is.read(data, 0, data.length)) != -1) {
            bs.write(data, 0, nRead);
        }

        bs.flush();

        return bs;
    }
}

Related

  1. getStreamBytes(InputStream is)
  2. getStreamContent(InputStream stream)
  3. getStreamContentAsBytes(InputStream is)
  4. getStreamToBytes(InputStream stream)
  5. inputStream2ByteArray(InputStream input)
  6. inputStreamAsBytes(InputStream stream)
  7. inputStreamToArray(InputStream is)
  8. InputStreamTOByte(InputStream in)
  9. inputStreamToByte(InputStream in)