org.apache.cocoon.components.serializers.encoding
Class CompiledCharset

java.lang.Object
  extended by org.apache.cocoon.components.serializers.encoding.AbstractCharset
      extended by org.apache.cocoon.components.serializers.encoding.CompiledCharset
All Implemented Interfaces:
Charset, Verifier
Direct Known Subclasses:
CompiledEncoder

public abstract class CompiledCharset
extends AbstractCharset

Version:
CVS $Id: CompiledCharset.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Pier Fumagalli, February 2003

Field Summary
protected  byte[] encoding
          The encoding table of this Charset.
 
Constructor Summary
protected CompiledCharset(String name, String[] aliases)
          Create a new instance of this CompiledCharset.
protected CompiledCharset(String name, String[] aliases, byte[] encoding)
          Create a new instance of this CompiledCharset.
 
Method Summary
 boolean allows(char c)
          Check if the specified character is representable by this specifiec Charset instance.
protected  void compile()
          Compile the encoding table of this CompiledCharset.
protected abstract  boolean compile(char c)
          Return true or false wether this encoding can encode the specified character or not.
 
Methods inherited from class org.apache.cocoon.components.serializers.encoding.AbstractCharset
equals, equals, getAliases, getName, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

encoding

protected byte[] encoding
The encoding table of this Charset.

Constructor Detail

CompiledCharset

protected CompiledCharset(String name,
                          String[] aliases)
Create a new instance of this CompiledCharset.

After construction, the compile() method will have to be called for proper operation of this Charset.

Parameters:
name - This Charset name.
aliases - This Charset alias names.
Throws:
NullPointerException - If one of the arguments is null.

CompiledCharset

protected CompiledCharset(String name,
                          String[] aliases,
                          byte[] encoding)
                   throws NullPointerException,
                          IllegalArgumentException
Create a new instance of this CompiledCharset.

The encodings table passed to this constructor needs to be 8192 bytes long, or (in other words), must contain exactly 65536 bits.

As in the Java Programming Language a char can assume values between 0 (zero) and 65535 (inclusive), each bit in the specified array refers to a specific char value.

When this specific bit is set to 1 (one or true) we assume that the charset can encode the given character, while when the bit is set to 0 (zero or false), the character cannot be represented using this Charset.

For example, the US-ASCII Charset can represent only Java characters between 0 (zero) and 255 (inclusive), therefore the specified byte array will contain only 256 true bits.

To check if a character can be encoded by this Charset, given "c" as the character to verify, one can write this simple formula:

((encoding[c >> 3] & (1 << (c & 0x07))) > 0)

If the result of this operation is 0 (zero) the bit was set to zero, and therefore "c" cannot be represented in this Charset, while if the result is greater than 0 (zero) the character "c" can actually be represented by this Charset

Parameters:
name - This Charset name.
aliases - This Charset alias names.
encoding - This Charset encoding table as specified above.
Throws:
NullPointerException - If one of the arguments is null.
IllegalArgumentException - If the length of the encoding table is not 8192 precisely.
Method Detail

allows

public boolean allows(char c)
Check if the specified character is representable by this specifiec Charset instance.


compile

protected final void compile()
Compile the encoding table of this CompiledCharset.

This method will invoke the compile(...) method for any possible value of a Java character (65536 times, from 0, zero, to 65535 inclusive), building the encoding table of the characters this Charset can successfully represent.


compile

protected abstract boolean compile(char c)
Return true or false wether this encoding can encode the specified character or not.

This method is equivalent to the allows(...) method, but it will be called upon construction of the encoding table.



Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.