- int currentByte;
- int currentBytePointer;
-
- OutputStream outputStream;
-
- public BitOutputStream(final OutputStream outputStream) {
- currentByte = 0;
- currentBytePointer = 0;
- this.outputStream = outputStream;
- };
-
- public void finishByte() throws IOException {
- if (currentBytePointer != 0) {
- outputStream.write(currentByte);
- currentBytePointer = 0;
- }
- }
-
- public void storeBits(final int data, final int bitCount)
- throws IOException {
- for (int i = bitCount - 1; i >= 0; i--) {
-
- int mask = 1;
- mask = mask << i;
-
- final int currentBit = data & mask;
- currentByte = currentByte << 1;
-
- if (currentBit != 0)
- currentByte = currentByte | 1;
- currentBytePointer++;
-
- if (currentBytePointer == 8) {
- currentBytePointer = 0;
- outputStream.write(currentByte);
- currentByte = 0;
- }
- }
- }
+ private final OutputStream outputStream;
+ private int currentByte;
+ private int currentBytePointer;
+
+ public BitOutputStream(final OutputStream outputStream) {
+ currentByte = 0;
+ currentBytePointer = 0;
+ this.outputStream = outputStream;
+ }
+
+ public void finishByte() throws IOException {
+ if (currentBytePointer != 0) {
+ outputStream.write(currentByte);
+ currentBytePointer = 0;
+ }
+ }
+
+ public void storeBits(final int data, final int bitCount)
+ throws IOException {
+ for (int i = bitCount - 1; i >= 0; i--) {
+
+ int mask = 1;
+ mask = mask << i;
+
+ final int currentBit = data & mask;
+ currentByte = currentByte << 1;
+
+ if (currentBit != 0)
+ currentByte = currentByte | 1;
+ currentBytePointer++;
+
+ if (currentBytePointer == 8) {
+ currentBytePointer = 0;
+ outputStream.write(currentByte);
+ currentByte = 0;
+ }
+ }
+ }