4 public class InputStreamToByteArray {
6 /** scratch space for isToByteArray() */
7 private static byte[] workspace = new byte[16 * 1024];
9 /** Trivial method to completely read an InputStream */
10 public static synchronized byte[] convert(InputStream is) throws IOException {
13 int numread = is.read(workspace, pos, workspace.length - pos);
14 if (numread == -1) break;
15 else if (pos + numread < workspace.length) pos += numread;
18 byte[] temp = new byte[workspace.length * 2];
19 System.arraycopy(workspace, 0, temp, 0, workspace.length);
23 byte[] ret = new byte[pos];
24 System.arraycopy(workspace, 0, ret, 0, pos);