public void writeBits ( final int value , final JBBPBitNumber bitNumber ) throws IOException { if ( this . bitBufferCount == 0 && bitNumber == JBBPBitNumber . BITS_8 ) { write ( value ) ; } else { final int initialMask ; int mask ; initialMask = 1 ; mask = initialMask << this . bitBufferCount ; int accum = value ; int i = bitNumber . getBitNumber ( ) ; while ( i > 0 ) { this . bitBuffer = this . bitBuffer | ( ( accum & 1 ) == 0 ? 0 : mask ) ; accum >>= 1 ; mask = mask << 1 ; i -- ; this . bitBufferCount ++ ; if ( this . bitBufferCount == 8 ) { this . bitBufferCount = 0 ; writeByte ( this . bitBuffer ) ; mask = initialMask ; this . bitBuffer = 0 ; } } } }
Write bits into the output stream .