Java Charset Create getCharset(String contentType)

Here you can find the source of getCharset(String contentType)

Description

get Charset

License

Apache License

Declaration

public static String getCharset(String contentType) 

Method Source Code

//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;
    }
}

Related

  1. getCharset(int cpgid, int gcsgid)
  2. getCharset(int ibmCharacterSetId)
  3. getCharSet(String charset)
  4. getCharset(String charsetName)
  5. getCharset(String charsetName)
  6. getCharset(String enc)
  7. getCharset(String encoding)
  8. getCharset(String encoding)
  9. getCharset(String name)