public static void setUserMetadataHeaders(JSONObject headers, Map<String, String> userMetadata) throws Exception {
    if (userMetadata != null) {
      CharsetEncoder encoder = StandardCharsets.US_ASCII.newEncoder();
      for (String key : userMetadata.keySet()) {
        String value = userMetadata.get(key);
        if (encoder.canEncode(value)) {
          headers.put(key, userMetadata.get(key));
        } else {
          String newKey = key.replaceFirst(RestUtils.Headers.USER_META_DATA_HEADER_PREFIX,
              RestUtils.Headers.USER_META_DATA_ENCODED_HEADER_PREFIX);
          headers.put(newKey, URLEncoder.encode(value, StandardCharsets.UTF_8.name()));
        }
      }
    }
  }
Sets entries from the passed in HashMap to the @{link JSONObject} headers
@param headers  {@link JSONObject} to which the new headers are to be added
@param userMetadata {@link Map} which has the new entries that has to be added
@throws org.json.JSONException
ambry-api/src/test/java/com/github/ambry/rest/RestUtilsTest.java