APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.org.apache.xml.internal.serializer

public final Class EncodingInfo

extends Object
Class Inheritance
Imports
java.io.UnsupportedEncodingException

Holds information about a given encoding, which is the Java name for the encoding, the equivalent ISO name.

An object of this type has two useful methods

isInEncoding(char ch);
which can be called if the character is not the high one in a surrogate pair and:
isInEncoding(char high, char low);
which can be called if the two characters from a high/low surrogate pair.

An EncodingInfo object is a node in a binary search tree. Such a node will answer if a character is in the encoding, and do so for a given range of unicode values (m_first to m_last). It will handle a certain range of values explicitly (m_explFirst to m_explLast). If the unicode point is before that explicit range, that is it is in the range m_first <= value < m_explFirst, then it will delegate to another EncodingInfo object for The root of such a tree, m_before. Likewise for values in the range m_explLast < value <= m_last, but delgating to m_after

Actually figuring out if a code point is in the encoding is expensive. So the purpose of this tree is to cache such determinations, and not to build the entire tree of information at the start, but only build up as much of the tree as is used during the transformation.

This Class is not a public API, and should only be used internally within the serializer.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
EncodingInfo.EncodingImpl

This class implements the

private static interface
EncodingInfo.InEncoding

A simple interface to isolate the implementation.

Field Summary

Modifier and TypeField and Description
pack-priv final String
javaName

The name used by the Java convertor.

private EncodingInfo.InEncoding
m_encoding

A helper object that we can ask if a single char, or a surrogate UTF-16 pair of chars that form a single character, is in this encoding.

pack-priv final String
name

The ISO encoding name.

Constructor Summary

AccessConstructor and Description
public
EncodingInfo(String
reference to the ISO name.
name
,
String
reference to the Java encoding name.
javaName
)

Create an EncodingInfo object based on the ISO name and Java name.

Method Summary

Modifier and TypeMethod and Description
private static boolean
inEncoding(char
the char in question, that is not a high char of a high/low surrogate pair.
ch
,
String
the Java name of the enocding.
encoding
)

This is heart of the code that determines if a given character is in the given encoding.

private static boolean
inEncoding(char
the high char of a high/low surrogate pair.
high
,
char
the low char of a high/low surrogate pair.
low
,
String
the Java name of the encoding.
encoding
)

This is heart of the code that determines if a given high/low surrogate pair forms a character that is in the given encoding.

private static boolean

Returns:

true if the character is in the encoding.
inEncoding
(char
the char that was converted using getBytes, or the first char of a high/low pair that was converted.
ch
,
byte[]
the bytes written out by the call to s.getBytes(encoding);
data
)

This method is the core of determining if character is in the encoding.

public boolean
isInEncoding(char
the char in question.
ch
)

This is not a public API.

public boolean
isInEncoding(char
a char that the a high char of a high/low surrogate pair.
high
,
char
a char that is the low char of a high/low surrogate pair.
low
)

This is not a public API.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

javaNameback to summary
pack-priv final String javaName

The name used by the Java convertor.

m_encodingback to summary
private EncodingInfo.InEncoding m_encoding

A helper object that we can ask if a single char, or a surrogate UTF-16 pair of chars that form a single character, is in this encoding.

nameback to summary
pack-priv final String name

The ISO encoding name.

Constructor Detail

EncodingInfoback to summary
public EncodingInfo(String name, String javaName)

Create an EncodingInfo object based on the ISO name and Java name. If both parameters are null any character will be considered to be in the encoding. This is useful for when the serializer is in temporary output state, and has no assciated encoding.

Parameters
name:String

reference to the ISO name.

javaName:String

reference to the Java encoding name.

Method Detail

inEncodingback to summary
private static boolean inEncoding(char ch, String encoding)

This is heart of the code that determines if a given character is in the given encoding. This method is probably expensive, and the answer should be cached.

This method is not a public API, and should only be used internally within the serializer.

Parameters
ch:char

the char in question, that is not a high char of a high/low surrogate pair.

encoding:String

the Java name of the enocding.

inEncodingback to summary
private static boolean inEncoding(char high, char low, String encoding)

This is heart of the code that determines if a given high/low surrogate pair forms a character that is in the given encoding. This method is probably expensive, and the answer should be cached.

This method is not a public API, and should only be used internally within the serializer.

Parameters
high:char

the high char of a high/low surrogate pair.

low:char

the low char of a high/low surrogate pair.

encoding:String

the Java name of the encoding.

inEncodingback to summary
private static boolean inEncoding(char ch, byte[] data)

This method is the core of determining if character is in the encoding. The method is not foolproof, because s.getBytes(encoding) has specified behavior only if the characters are in the specified encoding. However this method tries it's best.

Parameters
ch:char

the char that was converted using getBytes, or the first char of a high/low pair that was converted.

data:byte[]

the bytes written out by the call to s.getBytes(encoding);

Returns:boolean

true if the character is in the encoding.

isInEncodingback to summary
public boolean isInEncoding(char ch)

This is not a public API. It returns true if the char in question is in the encoding.

Parameters
ch:char

the char in question.

isInEncodingback to summary
public boolean isInEncoding(char high, char low)

This is not a public API. It returns true if the character formed by the high/low pair is in the encoding.

Parameters
high:char

a char that the a high char of a high/low surrogate pair.

low:char

a char that is the low char of a high/low surrogate pair.

com.sun.org.apache.xml.internal.serializer back to summary

private Class EncodingInfo.EncodingImpl

extends Object
implements InEncoding
Class Inheritance
  • java.lang.Object
  • com.sun.org.apache.xml.internal.serializer.EncodingInfo.EncodingImpl
All Implemented Interfaces
com.sun.org.apache.xml.internal.serializer.EncodingInfo.InEncoding

This class implements the

Field Summary

Modifier and TypeField and Description
private EncodingInfo.InEncoding
m_after

The object, of the same type as this one, that handles unicode values in a range after the range explictly handled by this object, and to which this object may delegate.

private final boolean[]
m_alreadyKnown

A flag to record if we already know the answer for the given unicode value.

private EncodingInfo.InEncoding
m_before

The object, of the same type as this one, that handles unicode values in a range before the range explictly handled by this object, and to which this object may delegate.

private final String
m_encoding

The encoding.

private final int
m_explFirst

m_explFirst through m_explLast is the range of unicode value that this object handles explicitly and does not delegate to a similar object.

private final int
private final int
m_first

m_first through m_last is the range of unicode values that this object will return an answer on.

private final boolean[]
m_isInEncoding

A table holding the answer on whether the given unicode value is in the encoding.

private final int
private static final int
RANGE

The number of unicode values explicitly handled by a single EncodingInfo object.

Constructor Summary

AccessConstructor and Description
private
private
EncodingImpl(String encoding, int first, int last, int codePoint)

Method Summary

Modifier and TypeMethod and Description
public boolean
isInEncoding(char ch1)

Implements com.sun.org.apache.xml.internal.serializer.EncodingInfo.InEncoding.isInEncoding.

Returns true if the char is in the encoding

public boolean
isInEncoding(char high, char low)

Implements com.sun.org.apache.xml.internal.serializer.EncodingInfo.InEncoding.isInEncoding.

Returns true if the high/low surrogate pair forms a character that is in the encoding.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

m_afterback to summary
private EncodingInfo.InEncoding m_after

The object, of the same type as this one, that handles unicode values in a range after the range explictly handled by this object, and to which this object may delegate.

m_alreadyKnownback to summary
private final boolean[] m_alreadyKnown

A flag to record if we already know the answer for the given unicode value.

m_beforeback to summary
private EncodingInfo.InEncoding m_before

The object, of the same type as this one, that handles unicode values in a range before the range explictly handled by this object, and to which this object may delegate.

m_encodingback to summary
private final String m_encoding

The encoding.

m_explFirstback to summary
private final int m_explFirst

m_explFirst through m_explLast is the range of unicode value that this object handles explicitly and does not delegate to a similar object.

m_explLastback to summary
private final int m_explLast
m_firstback to summary
private final int m_first

m_first through m_last is the range of unicode values that this object will return an answer on. It may delegate to a similar object with a different range

m_isInEncodingback to summary
private final boolean[] m_isInEncoding

A table holding the answer on whether the given unicode value is in the encoding.

m_lastback to summary
private final int m_last
RANGEback to summary
private static final int RANGE

The number of unicode values explicitly handled by a single EncodingInfo object. This value is tuneable, but is set to 128 because that covers the entire low range of ASCII type chars within a single object.

Constructor Detail

EncodingImplback to summary
private EncodingImpl()
EncodingImplback to summary
private EncodingImpl(String encoding, int first, int last, int codePoint)

Method Detail

isInEncodingback to summary
public boolean isInEncoding(char ch1)

Implements com.sun.org.apache.xml.internal.serializer.EncodingInfo.InEncoding.isInEncoding.

Doc from com.sun.org.apache.xml.internal.serializer.EncodingInfo.InEncoding.isInEncoding.

Returns true if the char is in the encoding

isInEncodingback to summary
public boolean isInEncoding(char high, char low)

Implements com.sun.org.apache.xml.internal.serializer.EncodingInfo.InEncoding.isInEncoding.

Doc from com.sun.org.apache.xml.internal.serializer.EncodingInfo.InEncoding.isInEncoding.

Returns true if the high/low surrogate pair forms a character that is in the encoding.

com.sun.org.apache.xml.internal.serializer back to summary

private Interface EncodingInfo.InEncoding

Known Direct Implementers
com.sun.org.apache.xml.internal.serializer.EncodingInfo.EncodingImpl

A simple interface to isolate the implementation. We could also use some new JRE 1.4 methods in another implementation provided we use reflection with them.

This interface is not a public API, and should only be used internally within the serializer.

Method Summary

Modifier and TypeMethod and Description
public boolean
isInEncoding(char ch)

Returns true if the char is in the encoding

public boolean
isInEncoding(char high, char low)

Returns true if the high/low surrogate pair forms a character that is in the encoding.

Method Detail

isInEncodingback to summary
public boolean isInEncoding(char ch)

Returns true if the char is in the encoding

isInEncodingback to summary
public boolean isInEncoding(char high, char low)

Returns true if the high/low surrogate pair forms a character that is in the encoding.