2 * Svjatoslav Commons - shared library of common functionality.
3 * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 3 of the GNU Lesser General Public License
7 * or later as published by the Free Software Foundation.
10 package eu.svjatoslav.commons.data;
13 * Read individual bits from the input stream.
16 import java.io.IOException;
17 import java.io.InputStream;
19 public class BitInputStream {
22 int currentBytePointer = -1;
24 InputStream inputStream;
26 public BitInputStream(final InputStream inputStream) {
27 this.inputStream = inputStream;
30 public int readBits(final int bitCount) throws IOException {
33 for (int i = 0; i < bitCount; i++) {
35 readableByte = readableByte << 1;
37 if (currentBytePointer == -1) {
38 currentBytePointer = 7;
39 currentByte = inputStream.read();
43 mask = mask << currentBytePointer;
45 final int currentBit = currentByte & mask;
48 readableByte = readableByte | 1;
55 public int readIntegerCompressed8() throws IOException {