Here you can find the source of readAll(InputStream bytes)
Parameter | Description |
---|---|
bytes | the InputStream of bytes to read |
Parameter | Description |
---|---|
IOException | if the stream fails |
public static byte[] readAll(InputStream bytes) throws IOException
//package com.java2s; /*/*w w w. ja v a 2 s . c om*/ * jndn-utils * Copyright (c) 2016, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU Lesser General Public License, * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for * more details. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /** * Read all of the bytes in an input stream. * * @param bytes the {@link InputStream} of bytes to read * @return an array of all bytes retrieved from the stream * @throws IOException if the stream fails */ public static byte[] readAll(InputStream bytes) throws IOException { ByteArrayOutputStream builder = new ByteArrayOutputStream(); int read = bytes.read(); while (read != -1) { builder.write(read); read = bytes.read(); } builder.flush(); bytes.close(); return builder.toByteArray(); } }