public void write ( int bits , int width ) throws IOException { if ( bits == 0 && width == 0 ) { return ; } if ( width <= 0 || width > 32 ) { throw new IOException ( "Bad write width." ) ; } while ( width > 0 ) { int actual = width ; if ( actual > this . vacant ) { actual = this . vacant ; } this . unwritten |= ( ( bits >>> ( width - actual ) ) & ( ( 1 << actual ) - 1 ) ) << ( this . vacant - actual ) ; width -= actual ; nrBits += actual ; this . vacant -= actual ; if ( this . vacant == 0 ) { this . out . write ( this . unwritten ) ; this . unwritten = 0 ; this . vacant = 8 ; } } }
Write some bits . Up to 32 bits can be written at a time .