Skip to content

Instantly share code, notes, and snippets.

@linxiaobai
Created July 15, 2019 09:24
Show Gist options
  • Save linxiaobai/68afbd3b864aa226b0a0a4a8c7ea6ad8 to your computer and use it in GitHub Desktop.
Save linxiaobai/68afbd3b864aa226b0a0a4a8c7ea6ad8 to your computer and use it in GitHub Desktop.
multiMap string to Map
private static final String MULTIMAP_PATTERN_REGEX = "(, |\\s*)(.*?)=\\[(.*?)]";
private static final Pattern MULTIMAP_PATTERN = Pattern.compile(MULTIMAP_PATTERN_REGEX);
public static Map<String, String> convertHeaderMultimapStringToHashMap(String text) {
Map<String, String> map = new HashMap<>();
text = text.substring(1, text.length() - 1);
Matcher matcher = MULTIMAP_PATTERN.matcher(text);
while (matcher.find()) {
map.put(matcher.group(2).toUpperCase(), matcher.group(3)); //header name ignore upper or lower case
}
return map;
}
@linxiaobai
Copy link
Author

example string : {Transfer-Encoding=[chunked], Content-Type=[application/json;charset=UTF-8]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment