+++ /dev/null
-package eu.svjatoslav.imagesqueeze.codec;
-
-/**
- * Read individual bits from the input stream.
- */
-
-import java.io.IOException;
-import java.io.InputStream;
-
-public class BitInputStream {
-
-
- int currentByte;
- int currentBytePointer = -1;
-
- InputStream inputStream;
-
- public BitInputStream(InputStream inputStream){
- this.inputStream = inputStream;
- }
-
- public int readBits(int bitCount) throws IOException {
-
- int readableByte = 0;
- for (int i=0; i < bitCount; i++){
-
- readableByte = readableByte << 1;
-
- if (currentBytePointer == -1){
- currentBytePointer = 7;
- currentByte = inputStream.read();
- }
-
- int mask = 1;
- mask = mask << currentBytePointer;
-
- int currentBit = currentByte & mask;
-
- if (currentBit != 0){
- readableByte = readableByte | 1;
- }
-
- currentBytePointer--;
- }
- return readableByte;
- }
-
- public int readIntegerCompressed8() throws IOException{
- if (readBits(1) == 0){
- return readBits(8);
- } else {
- return readBits(32);
- }
- }
-
-}