private static String hashBytes(MessageDigest hash, byte[] bytes) {
   hash.update(bytes);
   byte[] digest = hash.digest();
   StringBuilder builder = new StringBuilder();
   for (int b : digest) {
     builder.append(Integer.toHexString((b >> 4) & 0xf));
     builder.append(Integer.toHexString((b >> 0) & 0xf));
   }
   return builder.toString();
 }
  /** Build user's info to display on the screen */
  private String buildUserInfoDisplay(GraphUser user) {
    StringBuilder userInfo = new StringBuilder("");

    /** (name) - no special permissions required */
    userInfo.append(String.format("Name: %s\n", user.getName()));

    /** (birthday) - requires user_birthday permission */
    userInfo.append(String.format("Birthday: %s\n", user.getBirthday()));

    /** (location) - requires user_location permission */
    GraphPlace location = user.getLocation();
    if (location != null) {
      userInfo.append(String.format("Location: %s\n", location.getProperty("name")));
    }

    /** (locale) - no special permissions required */
    userInfo.append(String.format("Locale: %s\n", user.getProperty("locale")));

    /** (languages) - requires user_likes permission. */
    JSONArray languages = (JSONArray) user.getProperty("languages");
    if (languages != null && languages.length() > 0) {
      ArrayList<String> languageNames = new ArrayList<String>();
      for (int i = 0; i < languages.length(); i++) {
        JSONObject language = languages.optJSONObject(i);
        languageNames.add(language.optString("name"));
      }
      userInfo.append(String.format("Languages: %s\n", languageNames.toString()));
    }
    return userInfo.toString();
  }
  public static String readStreamToString(InputStream inputStream) throws IOException {
    BufferedInputStream bufferedInputStream = null;
    InputStreamReader reader = null;
    try {
      bufferedInputStream = new BufferedInputStream(inputStream);
      reader = new InputStreamReader(bufferedInputStream);
      StringBuilder stringBuilder = new StringBuilder();

      final int bufferSize = 1024 * 2;
      char[] buffer = new char[bufferSize];
      int n = 0;
      while ((n = reader.read(buffer)) != -1) {
        stringBuilder.append(buffer, 0, n);
      }

      return stringBuilder.toString();
    } finally {
      closeQuietly(bufferedInputStream);
      closeQuietly(reader);
    }
  }