public static byte[] toByteArray(InputStream in) throws IOException {
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  copy(in,out);
  return out.toByteArray();
}

public static byte [ ] toByteArray ( InputStream in ) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; copy ( in , out ) ; return out . toByteArray ( ) ; }
reads all bytes from an input stream into a byte array . does not close the stream .
