Java Utililty Methods Charset Create

List of utility methods to do Charset Create

Description

The list of methods to do Charset Create are organized into topic(s).

Method

StringgetCharsetName(String location)
get Charset Name
Matcher matcher = REMOTE_PATH_PATTERN.matcher(location);
if (matcher.matches() && matcher.groupCount() > 2) {
    return Charset.forName(matcher.group(4)).name();
} else {
    return null;
CharsetgetCharsetOrDefault(String charsetName)
get Charset Or Default
Charset charset = null;
if (Charset.isSupported(charsetName)) {
    charset = Charset.forName(charsetName);
} else {
    charset = Charset.defaultCharset();
return charset;
CharsetgetDefaultCharset()
get Default Charset
String charsetName;
try {
    charsetName = System.getProperty("file.encoding");
} catch (SecurityException e) {
    charsetName = null;
if (charsetName == null) {
    charsetName = new InputStreamReader(System.in).getEncoding();
...
CharsetgetDefaultCharset()
Returns the system's default charset.
if (defaultCharset == null)
    defaultCharset = Charset
            .forName(new InputStreamReader(new ByteArrayInputStream(new byte[0])).getEncoding());
return defaultCharset;
StringgetDefaultCharsetName()
get Default Charset Name
return Charset.defaultCharset().name();
CharsetgetDefaultSystemCharset()
get Default System Charset
return Charset.forName(System.getProperty("file.encoding"));
intgetEncodedStringLength(String str)
get Encoded String Length
return encodeString(str).length;
StringgetEncodedUrl(String unEncodedUrl)
get Encoded Url
try {
    return URLEncoder.encode(unEncodedUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException ex) {
    return ERR_ENCODE_STRING;
CharsetEncodergetEncoder()
get Encoder
CharsetEncoder encoder = (CharsetEncoder) getReference(encoderCache);
if (encoder == null) {
    encoder = UTF8.newEncoder();
    setReference(encoderCache, encoder);
return encoder;
CharsetEncodergetEncoder()
get Encoder
SoftReference<CharsetEncoder> sr = encoder.get();
if (sr == null || sr.get() == null) {
    CharsetEncoder ce = UTF8_CHARSET.newEncoder();
    encoder.set(new SoftReference<CharsetEncoder>(ce));
    return ce;
} else {
    return sr.get();