Created
December 17, 2011 22:15
-
-
Save casidiablo/1491575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert a Map to UrlEncodedFormEntity | |
* | |
* @param parameters A Map of key:value | |
* @return UrlEncodedFormEntity using UTF-8 encoding | |
* @throws java.io.UnsupportedEncodingException | |
* if UTF-8 encoding is not supported | |
*/ | |
private static UrlEncodedFormEntity mapToEntity(Map<String, String> parameters) | |
throws UnsupportedEncodingException { | |
if (parameters == null) { | |
throw new IllegalArgumentException("Invalid parameters unable map to Entity"); | |
} | |
if (parameters.isEmpty()) { | |
return null; | |
} | |
ArrayList<NameValuePair> parametersList = new ArrayList<NameValuePair>(); | |
for (@SuppressWarnings("rawtypes") Map.Entry element : parameters.entrySet()) { | |
NameValuePair nameValuePair = new BasicNameValuePair((String) element.getKey(), (String) element.getValue()); | |
parametersList.add(nameValuePair); | |
} | |
return new UrlEncodedFormEntity(parametersList, HTTP.UTF_8); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment