It's my mistake. This should be `bb.limit() - bb.remaining()`. Thanks.