public int readUnary() throws IOException {

		int bitBuffer = this.bitBuffer;
		int bitCount = this.bitCount;
		int unaryCount = 0;

		for (;;) {
			if (bitCount > 0) {
				bitCount--;
			} else  {
				int byteRead = this.inputStream.read();

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

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

			if (((bitBuffer & (1 << bitCount))) == 0) {
				this.bitBuffer = bitBuffer;
				this.bitCount = bitCount;
				return unaryCount;
			}
			unaryCount++;
		}

	}