Index: D:/harmony/HarmonyCodeBase/org.apache.harmony.nio_char/src/main/java/java/nio/charset/Charset.java =================================================================== --- D:/harmony/HarmonyCodeBase/org.apache.harmony.nio_char/src/main/java/java/nio/charset/Charset.java (revision 380293) +++ D:/harmony/HarmonyCodeBase/org.apache.harmony.nio_char/src/main/java/java/nio/charset/Charset.java (working copy) @@ -651,10 +651,22 @@ * integer if larger than it, or 0 if equal to it */ public final int compareTo(Object obj) { - Charset that = (Charset) obj; - return this.canonicalName.compareToIgnoreCase(that.canonicalName); + Charset that = (Charset) obj; + return compareTo(that); } + /** + * Compares this charset with the given charset. + * + * @param charset + * the given object to be compared with + * @return a negative integer if less than the given object, a positive + * integer if larger than it, or 0 if equal to it + */ + public final int compareTo(Charset charset) { + return this.canonicalName.compareToIgnoreCase(charset.canonicalName); + } + /* * ------------------------------------------------------------------- * Methods overriding parent class Object @@ -696,6 +708,28 @@ return "Charset[" + this.canonicalName + "]"; //$NON-NLS-1$//$NON-NLS-2$ } + /** + * Gets the system default charset from jvm. + * + * @return the default charset + */ + public static Charset defaultCharset() { + Charset defaultCharset = null; + String encoding = (String) AccessController + .doPrivileged(new PrivilegedAction() { + public Object run() { + return System + .getProperty("file.encoding"); //$NON-NLS-1$ + } + }); + try { + defaultCharset = Charset.forName(encoding); + } catch (UnsupportedCharsetException e) { + defaultCharset = Charset.forName("UTF-8"); //$NON-NLS-1$ + } + return defaultCharset; + } + /** * A comparator that ignores case. */