This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 33225fa2 [IO-414] Don't write a BOM on every (or any) line #492
33225fa2 is described below

commit 33225fa2759163c61abdead4ae891b5e75e17fb9
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Oct 7 10:48:14 2023 -0400

    [IO-414] Don't write a BOM on every (or any) line #492
    
    Javadoc
---
 src/changes/changes.xml                          | 5 ++++-
 src/main/java/org/apache/commons/io/IOUtils.java | 7 ++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c94646ae..08a04465 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -71,7 +71,10 @@ The <action> type attribute can be add,update,fix,remove.
         StreamIterator fails to close its internal Stream.
       </action>
       <action dev="ggregory" type="fix" issue="IO-814" due-to="Elliotte Rusty 
Harold, Gary Gregory">
-        Don't throw UncheckedIOException #491. 
+        Don't throw UncheckedIOException #491.
+      </action>
+      <action dev="ggregory" type="fix" issue="IO-414" due-to="Elliotte Rusty 
Harold, Gary Gregory">
+        Don't write a BOM on every (or any) line #492.
       </action>
       <!-- ADD -->
       <!-- UPDATE -->
diff --git a/src/main/java/org/apache/commons/io/IOUtils.java 
b/src/main/java/org/apache/commons/io/IOUtils.java
index 3382e865..dfc9ff57 100644
--- a/src/main/java/org/apache/commons/io/IOUtils.java
+++ b/src/main/java/org/apache/commons/io/IOUtils.java
@@ -3828,10 +3828,11 @@ public class IOUtils {
      * Writes the {@link #toString()} value of each item in a collection to
      * an {@link OutputStream} line by line, using the specified character
      * encoding and the specified line ending.
-     *
+     * <p>
      * UTF-16 is written big-endian with no byte order mark.
      * For little endian, use UTF-16LE. For a BOM, write it to the stream
      * before calling this method.
+     * </p>
      *
      * @param lines the lines to write, null entries produce blank lines
      * @param lineEnding the line separator to use, null is system default
@@ -3842,14 +3843,14 @@ public class IOUtils {
      * @since 2.3
      */
     public static void writeLines(final Collection<?> lines, String 
lineEnding, final OutputStream output,
-                                  final Charset charset) throws IOException {
+            final Charset charset) throws IOException {
         if (lines == null) {
             return;
         }
         if (lineEnding == null) {
             lineEnding = System.lineSeparator();
         }
-        Charset cs = Charsets.toCharset(charset);
+        Charset cs = 
StandardCharsets.UTF_16.equals(Charsets.toCharset(charset)) ? 
StandardCharsets.UTF_16 : StandardCharsets.UTF_16BE;
         // don't write a BOM
         if (cs == StandardCharsets.UTF_16) {
             cs = StandardCharsets.UTF_16BE;

Reply via email to