protected byte[] inputStreamToByteArray(InputStream is) throws IOException {
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  int next=is.read();
  while (next > -1) {
    bos.write(next);
    next=is.read();
  }
  bos.flush();
  is.close();
  return bos.toByteArray();
}

protected byte [ ] inputStreamToByteArray ( InputStream is ) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; int next = is . read ( ) ; while ( next > - 1 ) { bos . write ( next ) ; next = is . read ( ) ; } bos . flush ( ) ; is . close ( ) ; return bos . toByteArray ( ) ; }
reads an input stream into a byte array
