public static byte[] readAll(InputStream inputStream) throws IOException {
  ByteArrayOutputStream outputStream=new ByteArrayOutputStream();
  byte[] buffer=new byte[1024];
  int k=0;
  for (; (k=inputStream.read(buffer)) != -1; ) {
    outputStream.write(buffer,0,k);
  }
  return outputStream.toByteArray();
}

public static byte [ ] readAll ( InputStream inputStream ) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream ( ) ; byte [ ] buffer = new byte [ 1024 ] ; int k = 0 ; for ( ; ( k = inputStream . read ( buffer ) ) != - 1 ; ) { outputStream . write ( buffer , 0 , k ) ; } return outputStream . toByteArray ( ) ; }
reads all contents of the input stream .
