private long ReadHuffSym(int[] table, int[] lengths, long nsyms, long nbits, BitBuffer bitbuf) {
		long i, j;
		bitbuf.EnsureBits(16);
		if ((i = table[(int)bitbuf.PeekBits((int)nbits)]) >= nsyms) {
			j = (1 << (int)((((4)) * 8) - nbits));
			do {
				j >>= 1;
				i <<= 1;
				i |= (bitbuf.GetBuffer() & j) != 0 ? (long)1 : 0;
				if (j == 0) return 0; // T O D O throw proper exception
			} while ((i = table[(int)i]) >= nsyms);
		}
		j = lengths[(int)i];
		bitbuf.RemoveBits((byte)j);

		return i;
	}