docs: @SuppressWarnings({"checkstyle:cyclomaticcomplexity", "checkstyle:magicnumber"})
  	public void writeRecord(AttributeProvider element) throws IOException, AttributeException {
  
  		if (this.columns == null) {
  			throw new MustCallWriteHeaderFunctionException();
  		}
  
  		//Field deleted flag (value : 2Ah (*) => Record is deleted, 20h (blank) => Record is valid)
  		this.stream.writeByte(0x20);
  
  		for (final DBaseFileField field : this.columns) {
  			// Get attribute
  			final DBaseFieldType dbftype = field.getType();
  			final String fieldName = field.getName();
  
  			AttributeValue attr = element != null ? element.getAttribute(fieldName) : null;
  
  			if (attr == null) {
  				attr = new AttributeValueImpl(dbftype.toAttributeType());
  				attr.setToDefault();
  			} else {
  				if (attr.isAssigned()) {
  					attr = new AttributeValueImpl(attr);
  					attr.cast(dbftype.toAttributeType());
  				} else {
  					attr = new AttributeValueImpl(attr);
  					attr.setToDefaultIfUninitialized();
  				}
  			}
  
  			// Write value
  			switch (dbftype) {
  			case BOOLEAN:
  				writeDBFBoolean(attr.getBoolean());
  				break;
  			case DATE:
  				writeDBFDate(attr.getDate());
  				break;
  			case STRING:
  				writeDBFString(attr.getString(), field.getLength(), (byte) ' ');
  				break;
  			case INTEGER_2BYTES:
  				writeDBFInteger((short) attr.getInteger());
  				break;
  			case INTEGER_4BYTES:
  				writeDBFLong((int) attr.getInteger());
  				break;
  			case DOUBLE:
  				writeDBFDouble(attr.getReal());
  				break;
  			case FLOATING_NUMBER:
  			case NUMBER:
  				if (attr.getType() == AttributeType.REAL) {
  					writeDBFNumber(attr.getReal(), field.getLength(), field.getDecimalPointPosition());
  				} else {
  					writeDBFNumber(attr.getInteger(), field.getLength(), field.getDecimalPointPosition());
  				}
  				break;
  			case BINARY:
  			case GENERAL:
  			case MEMORY:
  			case PICTURE:
  			case VARIABLE:
  				// not yet supported
  				writeDBFString((String) null, 10, (byte) 0);
  				break;
  			default:
  				throw new IllegalStateException();
  			}
  		}
  
  		// Be sure that the memory was not fully filled by the saving process
  		if (element != null) {
  			element.freeMemory();
  		}
  	}