Here you can find the source of getBytes(final InputStream is)
Parameter | Description |
---|---|
the | InputStream |
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] getBytes(final InputStream is) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { /**/*from w w w. j a v a 2s. c o m*/ * Reads an InputStream and returns the read byte[] * * @param the InputStream * @return the read byte[] * @throws IOException */ public static byte[] getBytes(final InputStream is) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int a = 0; while ((a = is.read(buffer)) != -1) { baos.write(buffer, 0, a); } baos.close(); buffer = null; return baos.toByteArray(); } }