EncodingInfopublic class EncodingInfo extends Object This class represents an encoding. |
Fields Summary |
---|
private static Method | fgGetConverterMethod | private static Method | fgCanConvertMethod | private static boolean | fgConvertersAvailable | private Object[] | fArgsForMethod | String | ianaName | String | javaName | int | lastPrintable | Object | fCharToByteConverter | boolean | fHaveTriedCToB | Charset | nioCharset | CharsetEncoder | nioCharEncoder |
Constructors Summary |
---|
public EncodingInfo(String ianaName, String javaName, int lastPrintable)Creates new EncodingInfo instance.
this.ianaName = ianaName;
this.javaName = EncodingMap.getIANA2JavaMapping(ianaName);
this.lastPrintable = lastPrintable;
try{
nioCharset = Charset.forName(this.javaName);
if(nioCharset.canEncode())
nioCharEncoder = nioCharset.newEncoder();
}catch(IllegalCharsetNameException ie){
nioCharset = null;
nioCharEncoder = null;
}catch(UnsupportedCharsetException ue){
nioCharset = null;
nioCharEncoder = null;
}
|
Methods Summary |
---|
public java.lang.String | getIANAName()Returns a MIME charset name of this encoding.
return this.ianaName;
| public java.io.Writer | getWriter(java.io.OutputStream output)Returns a writer for this encoding based on
an output stream.
// this should always be true!
if (javaName != null)
return new OutputStreamWriter(output, javaName);
javaName = EncodingMap.getIANA2JavaMapping(ianaName);
if(javaName == null)
// use UTF-8 as preferred encoding
return new OutputStreamWriter(output, "UTF8");
return new OutputStreamWriter(output, javaName);
| public boolean | isPrintable(char ch)Checks whether the specified character is printable or not
in this encoding.
if(ch <= this.lastPrintable)
return true;
if(nioCharEncoder != null)
return nioCharEncoder.canEncode(ch);
//We should not reach here , if we reach due to
//charset not supporting encoding then fgConvertersAvailable
//should take care of returning false.
if(fCharToByteConverter == null) {
if(fHaveTriedCToB || !fgConvertersAvailable) {
// forget it; nothing we can do...
return false;
}
if (fArgsForMethod == null) {
fArgsForMethod = new Object [1];
}
// try and create it:
try {
fArgsForMethod[0] = javaName;
fCharToByteConverter = fgGetConverterMethod.invoke(null, fArgsForMethod);
} catch(Exception e) {
// don't try it again...
fHaveTriedCToB = true;
return false;
}
}
try {
fArgsForMethod[0] = new Character(ch);
return ((Boolean) fgCanConvertMethod.invoke(fCharToByteConverter, fArgsForMethod)).booleanValue();
} catch (Exception e) {
// obviously can't use this converter; probably some kind of
// security restriction
fCharToByteConverter = null;
fHaveTriedCToB = false;
return false;
}
| public static void | testJavaEncodingName(java.lang.String name)
final byte [] bTest = {(byte)'v", (byte)'a", (byte)'l", (byte)'i", (byte)'d"};
String s = new String(bTest, name);
|
|