Skip to content

Commit 33225fa

Browse files
committed
[IO-414] Don't write a BOM on every (or any) line #492
Javadoc
1 parent 469ef76 commit 33225fa

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/changes/changes.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ The <action> type attribute can be add,update,fix,remove.
7171
StreamIterator fails to close its internal Stream.
7272
</action>
7373
<action dev="ggregory" type="fix" issue="IO-814" due-to="Elliotte Rusty Harold, Gary Gregory">
74-
Don't throw UncheckedIOException #491.
74+
Don't throw UncheckedIOException #491.
75+
</action>
76+
<action dev="ggregory" type="fix" issue="IO-414" due-to="Elliotte Rusty Harold, Gary Gregory">
77+
Don't write a BOM on every (or any) line #492.
7578
</action>
7679
<!-- ADD -->
7780
<!-- UPDATE -->

src/main/java/org/apache/commons/io/IOUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,10 +3828,11 @@ public static void writeLines(final Collection<?> lines, final String lineEnding
38283828
* Writes the {@link #toString()} value of each item in a collection to
38293829
* an {@link OutputStream} line by line, using the specified character
38303830
* encoding and the specified line ending.
3831-
*
3831+
* <p>
38323832
* UTF-16 is written big-endian with no byte order mark.
38333833
* For little endian, use UTF-16LE. For a BOM, write it to the stream
38343834
* before calling this method.
3835+
* </p>
38353836
*
38363837
* @param lines the lines to write, null entries produce blank lines
38373838
* @param lineEnding the line separator to use, null is system default
@@ -3842,14 +3843,14 @@ public static void writeLines(final Collection<?> lines, final String lineEnding
38423843
* @since 2.3
38433844
*/
38443845
public static void writeLines(final Collection<?> lines, String lineEnding, final OutputStream output,
3845-
final Charset charset) throws IOException {
3846+
final Charset charset) throws IOException {
38463847
if (lines == null) {
38473848
return;
38483849
}
38493850
if (lineEnding == null) {
38503851
lineEnding = System.lineSeparator();
38513852
}
3852-
Charset cs = Charsets.toCharset(charset);
3853+
Charset cs = StandardCharsets.UTF_16.equals(Charsets.toCharset(charset)) ? StandardCharsets.UTF_16 : StandardCharsets.UTF_16BE;
38533854
// don't write a BOM
38543855
if (cs == StandardCharsets.UTF_16) {
38553856
cs = StandardCharsets.UTF_16BE;

0 commit comments

Comments
 (0)