Name: skT88420 Date: 05/25/99
The following is a proposal for a new class called "java.io.Encoding".
If implemented as I've outlined, it would provide the following
benefits to the Java platform:
1 - The ability to determine which encodings are supported by the
current platform.
2 - The ability to determine the default native encoding (this is
currently logged as RFE 4175635)
3 - The ability to determine if a given encoding is reversible
(this is logged as RFE 4216686)
// java/io/Encoding.java
package java.io;
/**
* Provides information about file encodings supported by the
* system. It is not possible to sub-class this class, nor is
* it possible to create new instances except via the
* getEncoding method.
*/
public class Encoding {
// Add constants for common encodings which are guaranteed
// to be available on ALL platforms...
public static final Encoding ISO8859_1;
public static final Encoding UTF8;
public static final Encoding UTF16;
// more...
/** Hidden constructor */
private Encoding();
/**
* Returns a list of the supported encodings on this platform
*/
public static Encoding[] getSupportedEncodings();
/**
* Returns the default encoding for the platform
*/
public static Encoding getDefaultEncoding();
/**
* Changes the default encoding. This may or may not be a
* good thing to have
*/
public static void setDefaultEncoding(Encoding newDefault);
/**
* Returns a shared instance of the Encoding object for
* the given encoding.
*/
public static Encoding getEncoding(String name) throws UnsupportedEncodingException;
/**
* Returns the encoding's name ie "8859_1" or "UTF8"
*/
public String getName();
/**
* Returns a short description of the encoding. This should
* probably be localized. ie "Windows Latin 1"
*/
public String getDescription();
/**
* As above but using the given locale
*/
public String getDescription(java.util.Locale locale);
/**
* Returns true if there is a one-to-one correspondence of
* bytes to characters. See RFE 4216686
*/
public boolean isReversible();
/**
* Returns getName()
*/
public String toString();
}
In addition, any constructors which currently take an encoding
name as a string should be overridden with versions that take
an Encoding object. I suggest deprecating the old constructors
in favor of using Encoding objects.
(Review ID: 83464)
======================================================================