diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index d1db876e..7cb542cd 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -521,28 +521,75 @@ public final class CSVFormat implements Serializable { } /** - * Sets the header comments set to the given values. The comments will be printed first, before the headers. This setting is ignored by the parser. - * + * Sets the header comments to the given values before the CSV data. + *
+ * This setting is ignored by the parser. + *
+ *+ * Comments are printed first, before headers. + *
+ *+ * Use {@link Builder#setCommentMarker(char)} or {@link Builder#setCommentMarker(Character)} to set the comment marker written at the start of + * each comment line. + *
+ *+ * If the comment marker is not set, then the header comments are ignored. + *
+ *+ * For example: + *
*- * builder.setHeaderComments("Generated by Apache Commons CSV.", Instant.now()); + * builder.setCommentMarker('#') + * .setHeaderComments("Generated by Apache Commons CSV", Instant.ofEpochMilli(0)); + *+ *
+ * writes: + *
+ *+ * # Generated by Apache Commons CSV. + * # 1970-01-01T00:00:00Z ** - * @param headerComments the headerComments which will be printed by the Printer before the actual CSV data. + * @param headerComments the headerComments which will be printed by the Printer before the CSV data. * @return This instance. */ + public Builder setHeaderComments(final Object... headerComments) { this.headerComments = CSVFormat.clone(toStringArray(headerComments)); return this; } /** - * Sets the header comments set to the given values. The comments will be printed first, before the headers. This setting is ignored by the parser. - * + * Sets the header comments to the given values before the CSV data. + *
+ * This setting is ignored by the parser. + *
+ *+ * Comments are printed first, before headers. + *
+ *+ * Use {@link Builder#setCommentMarker(char)} or {@link Builder#setCommentMarker(Character)} to set the comment marker written at the start of + * each comment line. + *
+ *+ * If the comment marker is not set, then the header comments are ignored. + *
+ *+ * For example: + *
*- * Builder.setHeaderComments("Generated by Apache Commons CSV.", Instant.now()); + * builder.setCommentMarker('#') + * .setHeaderComments("Generated by Apache Commons CSV", Instant.ofEpochMilli(0).toString()); + *+ *
+ * writes: + *
+ *+ * # Generated by Apache Commons CSV. + * # 1970-01-01T00:00:00Z ** - * @param headerComments the headerComments which will be printed by the Printer before the actual CSV data. + * @param headerComments the headerComments which will be printed by the Printer before the CSV data. * @return This instance. */ public Builder setHeaderComments(final String... headerComments) {