Do this instead (it'll write the value as a vint and return how many bytes need to be added to the offset in one shot):
     offset += ByteUtil.vintToBytes(buffer, offset, entry.getValue().intValue())