FileDocCategorySizeDatePackage
GZIPInputStream.javaAPI DocphoneME MR2 API (J2ME)14739Wed May 02 18:00:34 BST 2007com.sun.perseus.platform

HuffmanTable

public class HuffmanTable extends Object

Fields Summary
GZIPInputStream
in
Hashtable
codeTable
int
minLen
Constructors Summary
public HuffmanTable(GZIPInputStream in, int[] lengths)

        this.in = in;
        this.codeTable = buildHuffman(lengths);
        this.minLen = Integer.MAX_VALUE;
        for (int i = 0; i < lengths.length; i++) {
            if (lengths[i] < minLen) {
                minLen = lengths[i];
            }
        }
    
Methods Summary
private static java.util.HashtablebuildHuffman(int[] tlen)

        int len = tlen.length;

        int[] bl_count = new int[33];
        int[] next_code = new int[33];
    
        int maxlen = -1;
        for (int i = 0; i < len; i++) {
            if (tlen[i] > maxlen) {
                maxlen = tlen[i];
            }
            ++bl_count[tlen[i]];
        }

        int code = 0;
        bl_count[0] = 0;
        for (int bits = 1; bits <= maxlen; bits++) {
            code = (code + bl_count[bits - 1]) << 1;
            next_code[bits] = code;
        }

        Hashtable codeTable = new Hashtable(len);
        for (int n = 0; n < len; n++) {
            int l = tlen[n];
            if (l != 0) {
                codeTable.put(getKey(next_code[l], l), new Integer(n));
                ++next_code[l];
            }
        }

        return codeTable;
    
private static java.lang.IntegergetKey(int code, int len)

        return new Integer((code << 8) | len);
    
private intgetVal(int code, int len)

        Object o = codeTable.get(getKey(code, len));
        if (o != null) {
            return ((Integer)o).intValue();
        }
        return -1;
    
public intreadSymbol()

        int code = in.readHuffmanBits(minLen);
        int len = minLen;

        while (true) {
            int val = getVal(code, len);
            if (val != -1) {
                return val;
            }
            code = (code << 1) | in.readBit();
            ++len;
        }