Index: java/nio/charset/Charset.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/nio/charset/Charset.java,v retrieving revision 1.17 diff -u -r1.17 Charset.java --- java/nio/charset/Charset.java 13 Apr 2005 13:19:53 -0000 1.17 +++ java/nio/charset/Charset.java 19 Apr 2005 22:33:10 -0000 @@ -59,6 +59,7 @@ /** * @author Jesse Rosenstock * @since 1.4 + * @status updated to 1.5 */ public abstract class Charset implements Comparable { @@ -116,6 +117,34 @@ } } + /** + * Returns the system default charset. + * + * This may be set by the user or VM with the file.encoding + * property. + */ + public static Charset defaultCharset() + { + String encoding; + try + { + encoding = System.getProperty("file.encoding"); + } catch(SecurityException e) { + encoding = "ISO-8859-1"; + } catch(IllegalArgumentException e) { + encoding = "ISO-8859-1"; + } + + try + { + return forName(encoding); + } catch(UnsupportedCharsetException e) { + } catch(IllegalCharsetNameException e) { + } catch(IllegalArgumentException e) { + } + throw new IllegalStateException("Can't get default charset!"); + } + public static boolean isSupported (String charsetName) { return charsetForName (charsetName) != null;