public static String readStringFromStream(InputStream stream) throws IOException {
  ByteArrayOutputStream byteString=new ByteArrayOutputStream();
  int c;
  int i=0;
  while ((c=stream.read()) != -1) {
    byteString.write(c);
    byte[] b=new byte[i + i];
    int readBytes=stream.read(b,i,i);
    for (int k=0; k < readBytes; k++) {
      byteString.write(b[k + i]);
    }
    if (readBytes != i) {
      i=i / 2;
    }
 else {
      i=i + 1;
    }
  }
  return byteString.toString();
}

public static String readStringFromStream ( InputStream stream ) throws IOException { ByteArrayOutputStream byteString = new ByteArrayOutputStream ( ) ; int c ; int i = 0 ; while ( ( c = stream . read ( ) ) != - 1 ) { byteString . write ( c ) ; byte [ ] b = new byte [ i + i ] ; int readBytes = stream . read ( b , i , i ) ; for ( int k = 0 ; k < readBytes ; k ++ ) { byteString . write ( b [ k + i ] ) ; } if ( readBytes != i ) { i = i / 2 ; } else { i = i + 1 ; } } return byteString . toString ( ) ; }
read a binary stream as string .
