Java examples for File Path IO:Byte Array
get Bytes From Stream
/******************************************************************************* * Copyright (c) 2009 IBM Corporation and others. * 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:// w ww .ja v a2 s . com * Matthew Hatem, IBM Corporation - initial API and implementation * Boris Bokowski, IBM Corporation - initial API and implementation *******************************************************************************/ //package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] getBytesFromStream(InputStream is) throws IOException { int BUFFER_SIZE = 8192; byte[] buffer = new byte[BUFFER_SIZE]; ByteArrayOutputStream os = new ByteArrayOutputStream(); int numRead = 0; while ((numRead = is.read(buffer)) > 0) { os.write(buffer, 0, numRead); } return os.toByteArray(); } }