X-Git-Url: http://www2.svjatoslav.eu/gitweb/?p=svjatoslav_commons.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fcommons%2Fdata%2FBitOutputStream.java;h=b356ea04a04393a927b73b8c5c1507dd8c32a726;hp=6730b2c51fad5843cdc168820e534128ea3ed49c;hb=9bf004ce4e9b5edff36c65fcc8cc0f303390d7fc;hpb=afaa928dd10304ee3e8e6bad3a377ced6a7b2f42 diff --git a/src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java b/src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java index 6730b2c..b356ea0 100755 --- a/src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java +++ b/src/main/java/eu/svjatoslav/commons/data/BitOutputStream.java @@ -18,44 +18,43 @@ import java.io.OutputStream; public class BitOutputStream { - 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; + } + } + } }