Java Charset Create getDefaultCharset()

Here you can find the source of getDefaultCharset()

Description

get Default Charset

License

Open Source License

Declaration

private static Charset getDefaultCharset() 

Method Source Code

//package com.java2s;
/*//from ww  w  . j  av a 2s. c om
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
 * published by JBoss Inc.; either version 1.0 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

import java.io.InputStreamReader;

import java.nio.charset.Charset;

public class Main {
    private static Charset getDefaultCharset() {
        String charsetName;
        try {
            // examine the de facto system property
            charsetName = System.getProperty("file.encoding");
        } catch (SecurityException e) {
            charsetName = null;
        }
        if (charsetName == null) {
            // take the long route
            charsetName = new InputStreamReader(System.in).getEncoding();
        }
        return Charset.forName(charsetName);
    }
}

Related

  1. getCharsetFromContentType(String contentType)
  2. getCharsetFromContentTypeString(String contentType)
  3. getCharsetList(List availableCharsets, Charset actualCharset)
  4. getCharsetName(String location)
  5. getCharsetOrDefault(String charsetName)
  6. getDefaultCharset()
  7. getDefaultCharsetName()
  8. getDefaultSystemCharset()
  9. getEncodedStringLength(String str)