if remaining is greater than Integer.MAX_VALUE, "(int) remaining" will be negative.