Here you can find the source of inputStreamToByteArray(InputStream ins)
Parameter | Description |
---|---|
ins | a parameter |
public static byte[] inputStreamToByteArray(InputStream ins)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**//from www . jav a 2 s . com * Returns the given {@link java.io.InputStream} as a byte array. * @param ins * @return */ public static byte[] inputStreamToByteArray(InputStream ins) { byte[] availableBytes = new byte[0]; try { byte[] buffer = new byte[4096]; ByteArrayOutputStream outs = new ByteArrayOutputStream(); int read = 0; while ((read = ins.read(buffer)) != -1) { outs.write(buffer, 0, read); } ins.close(); outs.close(); availableBytes = outs.toByteArray(); } catch (Exception e) { e.printStackTrace(); } return availableBytes; } }