Here you can find the source of getCharset(String contentType)
public static String getCharset(String contentType)
//package com.java2s; //License from project: Apache License import java.nio.charset.Charset; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { private static final Pattern patternForCharset = Pattern.compile("charset\\s*=\\s*['\"]*([^\\s;'\"]*)"); public static String getCharset(String contentType) { Matcher matcher = patternForCharset.matcher(contentType); if (matcher.find()) { String charset = matcher.group(1); if (Charset.isSupported(charset)) { return charset; }/* w ww. jav a 2 s .c o m*/ } return null; } }