public static int getVarInt ( ByteBuffer src ) { int tmp ; if ( ( tmp = src . get ( ) ) >= 0 ) { return tmp ; } int result = tmp & 0x7f ; if ( ( tmp = src . get ( ) ) >= 0 ) { result |= tmp << 7 ; } else { result |= ( tmp & 0x7f ) << 7 ; if ( ( tmp = src . get ( ) ) >= 0 ) { result |= tmp << 14 ; } else { result |= ( tmp & 0x7f ) << 14 ; if ( ( tmp = src . get ( ) ) >= 0 ) { result |= tmp << 21 ; } else { result |= ( tmp & 0x7f ) << 21 ; result |= ( tmp = src . get ( ) ) << 28 ; while ( tmp < 0 ) { // We get into this loop only in the case of overflow. // By doing this, we can call getVarInt() instead of // getVarLong() when we only need an int. tmp = src . get ( ) ; } } } } return result ; }
Reads a varint from the current position of the given ByteBuffer and returns the decoded value as 32 bit integer .