public int readBits (final int count) throws IOException {

		int bitBuffer = this.bitBuffer;
		int bitCount = this.bitCount;

		if (bitCount < count) {
			while (bitCount < count) {
				int byteRead = this.inputStream.read();

				if (byteRead < 0) {
					throw new BZip2Exception ("Insufficient data");
				}

				bitBuffer = (bitBuffer << 8) | byteRead;
				bitCount += 8;
			}

			this.bitBuffer = bitBuffer;
		}

		bitCount -= count;
		this.bitCount = bitCount;

		return (bitBuffer >>> bitCount) & ((1 << count) - 1);

	}