/** * Get the default encoding. Will first look at the LC_ALL, LC_CTYPE, and LANG environment variables, then the input.encoding * system property, then the default charset according to the JVM. * * @return The default encoding to use when none is specified. */ public static String getEncoding() { // Check for standard locale environment variables, in order of precedence, first. // See http://www.gnu.org/s/libc/manual/html_node/Locale-Categories.html for (String envOption : new String[]{"LC_ALL", "LC_CTYPE", "LANG"}) { String envEncoding = extractEncodingFromCtype(System.getenv(envOption)); if (envEncoding != null) { try { if (Charset.isSupported(envEncoding)) { return envEncoding; } } catch (IllegalCharsetNameException e) { continue; } } } return getString("input.encoding", Charset.defaultCharset().name()); }
/** * Get the default encoding. Will first look at the LC_ALL, LC_CTYPE, and LANG environment variables, then the input.encoding * system property, then the default charset according to the JVM. * * @return The default encoding to use when none is specified. */ public static String getEncoding() { // Check for standard locale environment variables, in order of precedence, first. // See http://www.gnu.org/s/libc/manual/html_node/Locale-Categories.html for (String envOption : new String[]{"LC_ALL", "LC_CTYPE", "LANG"}) { String envEncoding = extractEncodingFromCtype(System.getenv(envOption)); if (envEncoding != null) { try { if (Charset.isSupported(envEncoding)) { return envEncoding; } } catch (IllegalCharsetNameException e) { continue; } } } return getString("input.encoding", Charset.defaultCharset().name()); }