This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git
The following commit(s) were added to refs/heads/master by this push:
new 8379c942 Sort members.
8379c942 is described below
commit 8379c942b28e54985d7c073627ce3e84aae7bb44
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Jul 17 13:14:24 2026 -0700
Sort members.
---
.../apache/commons/csv/ExtendedBufferedReader.java | 34 +++++++++++-----------
.../org/apache/commons/csv/CSVPrinterTest.java | 22 +++++++-------
2 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
index 0c8b0e8d..a2d4f090 100644
--- a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
+++ b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
@@ -43,6 +43,23 @@ import
org.apache.commons.io.input.UnsynchronizedBufferedReader;
*/
final class ExtendedBufferedReader extends UnsynchronizedBufferedReader {
+ /**
+ * Measures the byte-order mark that {@code encoder} prepends to every
{@link CharsetEncoder#encode(CharBuffer)} call. Charsets such as {@code UTF-16}
emit
+ * a BOM each time, which would otherwise be counted once per character.
The BOM is the constant prefix shared by encoding one and two characters.
+ *
+ * @param encoder The encoder to measure.
+ * @return The byte-order mark length in bytes, or 0 when the encoder
writes none.
+ */
+ private static int measureBomLength(final CharsetEncoder encoder) {
+ try {
+ final int one = encoder.encode(CharBuffer.wrap(new char[] { 'a'
})).limit();
+ final int two = encoder.encode(CharBuffer.wrap(new char[] { 'a',
'a' })).limit();
+ return Math.max(0, 2 * one - two);
+ } catch (final CharacterCodingException e) {
+ return 0;
+ }
+ }
+
/** The last char returned */
private int lastChar = UNDEFINED;
@@ -166,23 +183,6 @@ final class ExtendedBufferedReader extends
UnsynchronizedBufferedReader {
throw new CharacterCodingException();
}
- /**
- * Measures the byte-order mark that {@code encoder} prepends to every
{@link CharsetEncoder#encode(CharBuffer)} call. Charsets such as {@code UTF-16}
emit
- * a BOM each time, which would otherwise be counted once per character.
The BOM is the constant prefix shared by encoding one and two characters.
- *
- * @param encoder The encoder to measure.
- * @return The byte-order mark length in bytes, or 0 when the encoder
writes none.
- */
- private static int measureBomLength(final CharsetEncoder encoder) {
- try {
- final int one = encoder.encode(CharBuffer.wrap(new char[] { 'a'
})).limit();
- final int two = encoder.encode(CharBuffer.wrap(new char[] { 'a',
'a' })).limit();
- return Math.max(0, 2 * one - two);
- } catch (final CharacterCodingException e) {
- return 0;
- }
- }
-
/**
* Returns the last character that was read as an integer (0 to 65535).
This will be the last character returned by any of the read methods. This will
not
* include a character read using the {@link #peek()} method. If no
character has been read then this will return {@link Constants#UNDEFINED}. If
the end of
diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
index 48698006..42360976 100644
--- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
@@ -1107,6 +1107,17 @@ class CSVPrinterTest {
}
}
+ @Test
+ void testMultiLineCommentWithoutRecordSeparator() throws IOException {
+ // A null record separator writes nothing between comment lines,
matching the record output path.
+ final CSVFormat format =
CSVFormat.DEFAULT.builder().setCommentMarker('#').setRecordSeparator(null).get();
+ final StringWriter sw = new StringWriter();
+ try (CSVPrinter printer = new CSVPrinter(sw, format)) {
+ printer.printComment("a\nb");
+ }
+ assertEquals("# a# b", sw.toString());
+ }
+
@Test
void testMultiLineCommentWithTrailingDelimiter() throws IOException {
// A comment is not a record, so the trailing delimiter must not
follow comment lines, or it becomes
@@ -1128,17 +1139,6 @@ class CSVPrinterTest {
}
}
- @Test
- void testMultiLineCommentWithoutRecordSeparator() throws IOException {
- // A null record separator writes nothing between comment lines,
matching the record output path.
- final CSVFormat format =
CSVFormat.DEFAULT.builder().setCommentMarker('#').setRecordSeparator(null).get();
- final StringWriter sw = new StringWriter();
- try (CSVPrinter printer = new CSVPrinter(sw, format)) {
- printer.printComment("a\nb");
- }
- assertEquals("# a# b", sw.toString());
- }
-
@Test
void testMySqlNullOutput() throws IOException {
Object[] s = new String[] { "NULL", null };