Here you can find the source of readBytes(InputStream s)
Parameter | Description |
---|---|
IOException | an exception |
public static byte[] readBytes(InputStream s) throws IOException
//package com.java2s; /******************************************************************************* * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww . ja v a 2 s . c om*/ * IBM Corporation - initial API and implementation *******************************************************************************/ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { /** * read fully the contents of s and return a byte array holding the result * * @throws IOException */ public static byte[] readBytes(InputStream s) throws IOException { if (s == null) { throw new IllegalArgumentException("null s"); } ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] b = new byte[1024]; int n = s.read(b); while (n != -1) { out.write(b, 0, n); n = s.read(b); } byte[] bb = out.toByteArray(); out.close(); return bb; } }