Here you can find the source of getBytesFromStream(InputStream is)
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] getBytesFromStream(InputStream is) throws IOException
//package com.java2s; /*//from w w w . jav a2 s . c om * Copyright (C) 2006-2016 Talend Inc. - www.talend.com * * This source code is available under agreement available at * %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt * * You should have received a copy of the agreement along with this program; if not, write to Talend SA 9 rue Pages * 92150 Suresnes, France */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /** * Extracts a byte array from an InputStream * * @return the byte array * @throws IOException */ public static byte[] getBytesFromStream(InputStream is) throws IOException { if (is == null) { return null; } ByteArrayOutputStream bos = new ByteArrayOutputStream(); int b; while ((b = is.read()) != -1) { bos.write(b); } return bos.toByteArray(); } }