1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache Public Source License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
8 public class InputStreamToByteArray {
10 /** scratch space for isToByteArray() */
11 private static byte[] workspace = new byte[16 * 1024];
13 /** Trivial method to completely read an InputStream */
14 public static synchronized byte[] convert(InputStream is) throws IOException {
17 int numread = is.read(workspace, pos, workspace.length - pos);
18 if (numread == -1) break;
19 else if (pos + numread < workspace.length) pos += numread;
22 byte[] temp = new byte[workspace.length * 2];
23 System.arraycopy(workspace, 0, temp, 0, workspace.length);
27 byte[] ret = new byte[pos];
28 System.arraycopy(workspace, 0, ret, 0, pos);