Skip to content

Commit 8379c94

Browse files
committed
Sort members.
1 parent 18e1076 commit 8379c94

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@
4343
*/
4444
final class ExtendedBufferedReader extends UnsynchronizedBufferedReader {
4545

46+
/**
47+
* Measures the byte-order mark that {@code encoder} prepends to every {@link CharsetEncoder#encode(CharBuffer)} call. Charsets such as {@code UTF-16} emit
48+
* 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.
49+
*
50+
* @param encoder The encoder to measure.
51+
* @return The byte-order mark length in bytes, or 0 when the encoder writes none.
52+
*/
53+
private static int measureBomLength(final CharsetEncoder encoder) {
54+
try {
55+
final int one = encoder.encode(CharBuffer.wrap(new char[] { 'a' })).limit();
56+
final int two = encoder.encode(CharBuffer.wrap(new char[] { 'a', 'a' })).limit();
57+
return Math.max(0, 2 * one - two);
58+
} catch (final CharacterCodingException e) {
59+
return 0;
60+
}
61+
}
62+
4663
/** The last char returned */
4764
private int lastChar = UNDEFINED;
4865

@@ -166,23 +183,6 @@ private int getEncodedCharLength(final int previous, final int current) throws C
166183
throw new CharacterCodingException();
167184
}
168185

169-
/**
170-
* Measures the byte-order mark that {@code encoder} prepends to every {@link CharsetEncoder#encode(CharBuffer)} call. Charsets such as {@code UTF-16} emit
171-
* 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.
172-
*
173-
* @param encoder The encoder to measure.
174-
* @return The byte-order mark length in bytes, or 0 when the encoder writes none.
175-
*/
176-
private static int measureBomLength(final CharsetEncoder encoder) {
177-
try {
178-
final int one = encoder.encode(CharBuffer.wrap(new char[] { 'a' })).limit();
179-
final int two = encoder.encode(CharBuffer.wrap(new char[] { 'a', 'a' })).limit();
180-
return Math.max(0, 2 * one - two);
181-
} catch (final CharacterCodingException e) {
182-
return 0;
183-
}
184-
}
185-
186186
/**
187187
* 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
188188
* 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

src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,17 @@ void testMultiLineComment() throws IOException {
11071107
}
11081108
}
11091109

1110+
@Test
1111+
void testMultiLineCommentWithoutRecordSeparator() throws IOException {
1112+
// A null record separator writes nothing between comment lines, matching the record output path.
1113+
final CSVFormat format = CSVFormat.DEFAULT.builder().setCommentMarker('#').setRecordSeparator(null).get();
1114+
final StringWriter sw = new StringWriter();
1115+
try (CSVPrinter printer = new CSVPrinter(sw, format)) {
1116+
printer.printComment("a\nb");
1117+
}
1118+
assertEquals("# a# b", sw.toString());
1119+
}
1120+
11101121
@Test
11111122
void testMultiLineCommentWithTrailingDelimiter() throws IOException {
11121123
// A comment is not a record, so the trailing delimiter must not follow comment lines, or it becomes
@@ -1128,17 +1139,6 @@ void testMultiLineCommentWithTrailingDelimiter() throws IOException {
11281139
}
11291140
}
11301141

1131-
@Test
1132-
void testMultiLineCommentWithoutRecordSeparator() throws IOException {
1133-
// A null record separator writes nothing between comment lines, matching the record output path.
1134-
final CSVFormat format = CSVFormat.DEFAULT.builder().setCommentMarker('#').setRecordSeparator(null).get();
1135-
final StringWriter sw = new StringWriter();
1136-
try (CSVPrinter printer = new CSVPrinter(sw, format)) {
1137-
printer.printComment("a\nb");
1138-
}
1139-
assertEquals("# a# b", sw.toString());
1140-
}
1141-
11421142
@Test
11431143
void testMySqlNullOutput() throws IOException {
11441144
Object[] s = new String[] { "NULL", null };

0 commit comments

Comments
 (0)