private static byte[] toByteArray(InputStream inputStream) throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  byte buffer[]=new byte[8192];
  while (true) {
    int read=inputStream.read(buffer);
    if (read == -1) {
      break;
    }
    baos.write(buffer,0,read);
  }
  return baos.toByteArray();
}

private static byte [ ] toByteArray ( InputStream inputStream ) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; byte buffer [ ] = new byte [ 8192 ] ; while ( true ) { int read = inputStream . read ( buffer ) ; if ( read == - 1 ) { break ; } baos . write ( buffer , 0 , read ) ; } return baos . toByteArray ( ) ; }
fully reads the given inputstream and returns it as a byte array
