Created
July 15, 2019 09:24
-
-
Save linxiaobai/68afbd3b864aa226b0a0a4a8c7ea6ad8 to your computer and use it in GitHub Desktop.
multiMap string to Map
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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example string : {Transfer-Encoding=[chunked], Content-Type=[application/json;charset=UTF-8]}