FileDocCategorySizeDatePackage
EncodingInfo.javaAPI DocApache Xerces 3.0.111507Fri Sep 14 20:33:56 BST 2007org.apache.xml.serialize

EncodingInfo

public class EncodingInfo extends Object
This class represents an encoding.
deprecated
This class was deprecated in Xerces 2.9.0. It is recommended that new applications use the DOM Level 3 LSSerializer or JAXP's Transformation API for XML (TrAX) for serializing XML. See the Xerces documentation for more information.
version
$Id: EncodingInfo.java 476047 2006-11-17 04:27:45Z mrglavas $

Fields Summary
private Object[]
fArgsForMethod
String
ianaName
String
javaName
int
lastPrintable
Object
fCharsetEncoder
Object
fCharToByteConverter
boolean
fHaveTriedCToB
boolean
fHaveTriedCharsetEncoder
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;
    
Methods Summary
public java.lang.StringgetIANAName()
Returns a MIME charset name of this encoding.

        return this.ianaName;
    
public java.io.WritergetWriter(java.io.OutputStream output)
Returns a writer for this encoding based on an output stream.

return
A suitable writer
exception
UnsupportedEncodingException There is no convertor to support this encoding

        // 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 booleanisPrintable(char ch)
Checks whether the specified character is printable or not in this encoding.

param
ch a code point (0-0x10ffff)

        if (ch <= this.lastPrintable) {
            return true;
        }
        return isPrintable0(ch);
    
private booleanisPrintable0(char ch)
Checks whether the specified character is printable or not in this encoding. This method accomplishes this using a java.nio.CharsetEncoder. If NIO isn't available it will attempt use a sun.io.CharToByteConverter.

param
ch a code point (0-0x10ffff)

        
        // Attempt to get a CharsetEncoder for this encoding.
        if (fCharsetEncoder == null && CharsetMethods.fgNIOCharsetAvailable && !fHaveTriedCharsetEncoder) {
            if (fArgsForMethod == null) {
                fArgsForMethod = new Object [1];
            }
            // try and create the CharsetEncoder
            try {
                fArgsForMethod[0] = javaName;
                Object charset = CharsetMethods.fgCharsetForNameMethod.invoke(null, fArgsForMethod);
                if (((Boolean) CharsetMethods.fgCharsetCanEncodeMethod.invoke(charset, (Object[]) null)).booleanValue()) {
                    fCharsetEncoder = CharsetMethods.fgCharsetNewEncoderMethod.invoke(charset, (Object[]) null);
                }
                // This charset cannot be used for encoding, don't try it again...
                else {
                    fHaveTriedCharsetEncoder = true;
                } 
            } 
            catch (Exception e) {   
                // don't try it again...
                fHaveTriedCharsetEncoder = true;
            }
        }
        // Attempt to use the CharsetEncoder to determine whether the character is printable.
        if (fCharsetEncoder != null) {
            try {
                fArgsForMethod[0] = new Character(ch);
                return ((Boolean) CharsetMethods.fgCharsetEncoderCanEncodeMethod.invoke(fCharsetEncoder, fArgsForMethod)).booleanValue();
            } 
            catch (Exception e) {
                // obviously can't use this charset encoder; possibly a JDK bug
                fCharsetEncoder = null;
                fHaveTriedCharsetEncoder = false;
            }
        }
        
        // As a last resort try to use a sun.io.CharToByteConverter to
        // determine whether this character is printable. We will always
        // reach here on JDK 1.3 or below.
        if (fCharToByteConverter == null) {
            if (fHaveTriedCToB || !CharToByteConverterMethods.fgConvertersAvailable) {
                // forget it; nothing we can do...
                return false;
            }
            if (fArgsForMethod == null) {
                fArgsForMethod = new Object [1];
            }
            // try and create the CharToByteConverter
            try {
                fArgsForMethod[0] = javaName;
                fCharToByteConverter = CharToByteConverterMethods.fgGetConverterMethod.invoke(null, fArgsForMethod);
            } 
            catch (Exception e) {   
                // don't try it again...
                fHaveTriedCToB = true;
                return false;
            }
        }
        try {
            fArgsForMethod[0] = new Character(ch);
            return ((Boolean) CharToByteConverterMethods.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 voidtestJavaEncodingName(java.lang.String name)

        final byte [] bTest = {(byte)'v", (byte)'a", (byte)'l", (byte)'i", (byte)'d"};
        String s = new String(bTest, name);