1 16 package org.apache.cocoon.components.serializers.encoding; 17 18 24 public abstract class CompiledCharset extends AbstractCharset { 25 26 27 protected byte encoding[]; 28 29 39 protected CompiledCharset(String name, String aliases[]) { 40 super(name, aliases); 41 this.encoding = new byte[8192]; 42 for (int x = 0; x < this.encoding.length; x++) this.encoding[x] = 0; 43 } 44 45 91 protected CompiledCharset(String name, String aliases[], byte encoding[]) 92 throws NullPointerException , IllegalArgumentException { 93 super(name, aliases); 94 if (encoding == null) throw new NullPointerException ("Invalid table"); 95 if (encoding.length != 8192) { 96 throw new IllegalArgumentException ("Invalid encoding table size: " 97 + "current length is " + encoding.length + ", required 8192."); 98 } 99 this.encoding = encoding; 100 } 101 102 107 public boolean allows(char c) { 108 109 return((this.encoding[c >> 3] & (1 << (c & 0x07))) > 0); 110 } 111 112 120 protected final void compile() { 121 for (int x = 0; x <= Character.MAX_VALUE; x ++) { 122 if (this.compile((char)x)) { 123 int pos = x >> 3; 124 encoding[pos] = (byte) (encoding[pos] | (1 << (x & 0x07))); 125 } 126 } 127 } 128 129 137 protected abstract boolean compile(char c); 138 } 139 | Popular Tags |