/** * Returns the sequence of paddings used by each field of each record. * * @return the sequence of paddings used by each field of each record. */ char[] getFieldPaddings() { if (fieldLengths == null) { return null; } return fieldLengths.getFieldPaddings(this.getFormat()); }
/** * Returns the sequence of paddings used by each field of each record. * * @return the sequence of paddings used by each field of each record. */ char[] getFieldPaddings() { if (fieldLengths == null) { return null; } return fieldLengths.getFieldPaddings(getFormat()); }
protected void adjustColumnLengths(String[] headers, int[] lengths){ if(getWriterSettings().getFieldLengths() == null) { getWriterSettings().setFieldLengths(new FixedWidthFields(headers, lengths)); } }
/** * Creates a new instance initialized with the lengths of all fields in a fixed-width record. * * @param fieldLengths The number lengths of all fields in a fixed-width record. All lengths must be greater than 0. */ public FixedWidthFields(int... fieldLengths) { for (int i = 0; i < fieldLengths.length; i++) { addField(fieldLengths[i]); } }
Lookup[] getLookaheadFormats() { return Lookup.getLookupFormats(lookaheadFormats, getFormat()); }
Lookup[] getLookbehindFormats() { return Lookup.getLookupFormats(lookbehindFormats, getFormat()); }
char[] getFieldPaddings(FixedWidthFormat format) { char[] out = getFieldPaddings(); for (int i = 0; i < out.length; i++) { if (out[i] == '\0') { out[i] = format.getPadding(); } } return out; }
/** * Applies a custom padding character to a given list of fields * * @param padding the padding to apply * @param names the names of the fields that should use the given padding character */ public void setPadding(char padding, String... names) { for (String name : names) { int position = indexOf(name); setPadding(position, padding); } }
/** * Configures a given list of fields to retain the padding character in any parsed values, * overriding the any default set for the whole input in {@link FixedWidthParserSettings#getKeepPadding()} * * @param name the name of the first field that should keep the padding character * @param names the names of more fields that should keep the padding character */ public void keepPaddingOn(String name, String... names) { setKeepPaddingFlag(true, name, names); }
int[] getAllLengths() { if (fieldLengths == null) { return null; } return fieldLengths.getAllLengths(); }
/** * Returns the sequence of alignments to consider for each field of each record. * * @return the sequence of alignments to consider for each field of each record. */ FieldAlignment[] getFieldAlignments() { if (fieldLengths == null) { return null; } return fieldLengths.getFieldAlignments(); }
/** * Applies a custom padding character to a given list of fields * * @param padding the padding to apply * @param positions the positions of the fields that should use the given padding character */ public void setPadding(char padding, int... positions) { for (int position : positions) { setPadding(position, padding); } }
/** * Returns the sequence of lengths to be read by the parser to form a record. * * @return the sequence of lengths to be read by the parser to form a record. */ int[] getFieldLengths() { if (fieldLengths == null) { return null; } return fieldLengths.getFieldLengths(); }
private void setKeepPaddingFlag(boolean keep, int position, int... positions) { setPaddingToKeep(position, keep); for (int p : positions) { setPaddingToKeep(p, keep); } }
/** * Adds the length of the next field in a fixed-width record. This method can be chained like this: addField("field_1", 5).addField("field_2", 6)... * * @param name the name of the next field. It is not validated. * @param length the length of the next field. It must be greater than 0. * * @return the FixedWidthFields instance itself for chaining. */ public FixedWidthFields addField(String name, int length) { return addField(name, length, FieldAlignment.LEFT, '\0'); }
/** * Configures a given list of fields to retain the padding character in any parsed values, * overriding the any default set for the whole input in {@link FixedWidthParserSettings#getKeepPadding()} * * @param position the positions of the fields that should keep the padding character * @param positions additional positions */ public void keepPaddingOn(int position, int... positions) { setKeepPaddingFlag(true, position, positions); }
/** * Returns the sequence of field lengths to be written to form a record. * * @return the sequence of field lengths to be written to form a record. */ int[] getAllLengths() { if (fieldLengths == null) { return null; } return fieldLengths.getAllLengths(); }
/** * Adds the length of the next field in a fixed-width record. This method can be chained like this: addField(5).addField(6)... * * @param length the length of the next field. It must be greater than 0. * @param padding the representation of unused space in this field * * @return the FixedWidthFields instance itself for chaining. */ public FixedWidthFields addField(int length, char padding) { return addField(null, length, FieldAlignment.LEFT, padding); }
/** * Adds the length of the next field in a fixed-width record. This method can be chained like this: addField(5).addField(6)... * * @param length the length of the next field. It must be greater than 0. * @param alignment the alignment of the field * @param padding the representation of unused space in this field * * @return the FixedWidthFields instance itself for chaining. */ public FixedWidthFields addField(int length, FieldAlignment alignment, char padding) { return addField(null, length, alignment, padding); }
/** * Adds the length of the next field in a fixed-width record. This method can be chained like this: addField("field_1", 5).addField("field_2", 6)... * * @param name the name of the next field. It is not validated. * @param length the length of the next field. It must be greater than 0. * @param padding the representation of unused space in this field * * @return the FixedWidthFields instance itself for chaining. */ public FixedWidthFields addField(String name, int length, char padding) { return addField(name, length, FieldAlignment.LEFT, padding); }