diff options
Diffstat (limited to 'libjava/java/nio/charset/Charset.java')
-rw-r--r-- | libjava/java/nio/charset/Charset.java | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/libjava/java/nio/charset/Charset.java b/libjava/java/nio/charset/Charset.java index 5bb78f63ca9..c7672c1c3df 100644 --- a/libjava/java/nio/charset/Charset.java +++ b/libjava/java/nio/charset/Charset.java @@ -117,9 +117,24 @@ public abstract class Charset implements Comparable { return charsetForName (charsetName) != null; } - + + /** + * Returns the Charset instance for the charset of the given name. + * + * @param charsetName + * @return + * @throws UnsupportedCharsetException if this VM does not support + * the charset of the given name. + * @throws IllegalCharsetNameException if the given charset name is + * legal. + * @throws IllegalArgumentException if <code>charsetName</code> is null. + */ public static Charset forName (String charsetName) { + // Throws IllegalArgumentException as the JDK does. + if(charsetName == null) + throw new IllegalArgumentException("Charset name must not be null."); + Charset cs = charsetForName (charsetName); if (cs == null) throw new UnsupportedCharsetException (charsetName); @@ -132,19 +147,19 @@ public abstract class Charset implements Comparable * Retrieves a charset for the given charset name. * * @return A charset object for the charset with the specified name, or - * <code>null</code> if no such charset exists. + * <code>null</code> if no such charset exists. * * @throws IllegalCharsetNameException if the name is illegal */ - private static Charset charsetForName (String charsetName) + private static Charset charsetForName(String charsetName) { checkName (charsetName); return provider ().charsetForName (charsetName); } - public static SortedMap availableCharsets () + public static SortedMap availableCharsets() { - TreeMap charsets = new TreeMap (String.CASE_INSENSITIVE_ORDER); + TreeMap charsets = new TreeMap(String.CASE_INSENSITIVE_ORDER); for (Iterator i = provider ().charsets (); i.hasNext (); ) { @@ -152,15 +167,15 @@ public abstract class Charset implements Comparable charsets.put (cs.name (), cs); } - return Collections.unmodifiableSortedMap (charsets); + return Collections.unmodifiableSortedMap(charsets); } // XXX: we need to support multiple providers, reading them from // java.nio.charset.spi.CharsetProvider in the resource directory // META-INF/services - private static CharsetProvider provider () + private static CharsetProvider provider() { - return Provider.provider (); + return Provider.provider(); } public final String name () |