public int read(int width) throws IOException {
        if (width == 0) {
            return 0;
        }
        if (width < 0 || width > 32) {
            throw new IOException("Bad read width.");
        }
        int result = 0;
        while (width > 0) {
            if (this.available == 0) {
                this.unread = this.in.read();
                if (this.unread < 0) {
                    throw new IOException("Attempt to read past end.");
                }
                this.available = 8;
            }
            int take = width;
            if (take > this.available) {
                take = this.available;
            }
            result |= ((this.unread >>> (this.available - take)) &
                    ((1 << take) - 1)) << (width - take);
            this.nrBits += take;
            this.available -= take;
            width -= take;
        }
        return result;
    }
public int read ( int width ) throws IOException { if ( width == 0 ) { return 0 ; } if ( width < 0 || width > 32 ) { throw new IOException ( "Bad read width." ) ; } int result = 0 ; while ( width > 0 ) { if ( this . available == 0 ) { this . unread = this . in . read ( ) ; if ( this . unread < 0 ) { throw new IOException ( "Attempt to read past end." ) ; } this . available = 8 ; } int take = width ; if ( take > this . available ) { take = this . available ; } result |= ( ( this . unread > > > ( this . available - take ) ) & ( ( 1 << take ) - 1 ) ) << ( width - take ) ; this . nrBits += take ; this . available -= take ; width -= take ; } return result ; }
Read some bits.

@param width
The number of bits to read. (0..32)
@throws IOException
@return the bits