protected void processRow()

in src/main/java/com/univocity/parsers/fixed/FixedWidthWriter.java [192:291]


	protected void processRow(Object[] row) {
		if (row.length > 0 && lookaheadFormats != null || lookbehindFormats != null) {
			int dstBegin = 0;
			for (int i = 0; i < row.length && dstBegin < lookupChars.length; i++) {
				String value = String.valueOf(row[i]);
				int len = value.length();

				if (dstBegin + len > lookupChars.length) {
					len = lookupChars.length - dstBegin;
				}

				value.getChars(0, len, lookupChars, dstBegin);
				dstBegin += len;
			}

			for (int i = lookupChars.length - 1; i > dstBegin; i--) {
				lookupChars[i] = '\0';
			}

			boolean matched = false;
			if (lookaheadFormats != null) {
				for (int i = 0; i < lookaheadFormats.length; i++) {
					if (lookaheadFormats[i].matches(lookupChars)) {
						fieldLengths = lookaheadFormats[i].lengths;
						fieldAlignments = lookaheadFormats[i].alignments;
						fieldPaddings = lookaheadFormats[i].paddings;
						ignore = lookaheadFormats[i].ignore;
						matched = true;
						break;
					}
				}
				if (lookbehindFormats != null && matched) {
					lookbehindFormat = null;
					for (int i = 0; i < lookbehindFormats.length; i++) {
						if (lookbehindFormats[i].matches(lookupChars)) {
							lookbehindFormat = lookbehindFormats[i];
							break;
						}
					}
				}
			} else {
				for (int i = 0; i < lookbehindFormats.length; i++) {
					if (lookbehindFormats[i].matches(lookupChars)) {
						lookbehindFormat = lookbehindFormats[i];
						matched = true;
						fieldLengths = rootLengths;
						fieldAlignments = rootAlignments;
						fieldPaddings = rootPaddings;
						ignore = rootIgnore;
						break;
					}
				}
			}

			if (!matched) {
				if (lookbehindFormat == null) {
					if (rootLengths == null) {
						throw new TextWritingException("Cannot write with the given configuration. No default field lengths defined and no lookahead/lookbehind value match '" + new String(lookupChars) + '\'', getRecordCount(), row);
					}
					fieldLengths = rootLengths;
					fieldAlignments = rootAlignments;
					fieldPaddings = rootPaddings;
					ignore = rootIgnore;
				} else {
					fieldLengths = lookbehindFormat.lengths;
					fieldAlignments = lookbehindFormat.alignments;
					fieldPaddings = lookbehindFormat.paddings;
					ignore = lookbehindFormat.ignore;
				}
			}
		}

		if (expandRows) {
			row = expand(row, fieldLengths.length - ignoreCount, null);
		}

		final int lastIndex = fieldLengths.length < row.length ? fieldLengths.length : row.length;
		int off = 0;
		for (int i = 0; i < lastIndex + off; i++) {
			length = fieldLengths[i];
			if (ignore[i]) {
				off++;
				this.appender.fill(' ', length);
			} else {
				alignment = fieldAlignments[i];
				padding = fieldPaddings[i];
				if (writingHeaders) {
					if (defaultHeaderPadding) {
						padding = defaultPadding;
					}
					if (defaultHeaderAlignment != null) {
						alignment = defaultHeaderAlignment;
					}
				}
				String nextElement = getStringValue(row[i - off]);
				processElement(nextElement);
				appendValueToRow();
			}
		}
	}