1 package eu.svjatoslav.imagesqueeze.codec;
4 * Write individual bits to the output stream.
7 import java.io.IOException;
8 import java.io.OutputStream;
10 public class BitOutputStream {
13 int currentBytePointer;
15 OutputStream outputStream;
17 public BitOutputStream(OutputStream outputStream){
19 currentBytePointer = 0;
20 this.outputStream = outputStream;
24 public void storeBits(int data, int bitCount) throws IOException {
25 for (int i=bitCount-1; i >= 0; i--){
30 int currentBit = data & mask;
31 currentByte = currentByte << 1;
34 currentByte = currentByte | 1;
38 if (currentBytePointer == 8){
39 currentBytePointer = 0;
40 outputStream.write(currentByte);
46 public void storeIntegerCompressed8(int data) throws IOException{
56 public void finishByte() throws IOException {
57 if (currentBytePointer != 0){
58 outputStream.write(currentByte);
59 currentBytePointer = 0;