Skip to content

Commit 43594ce

Browse files
committed
Revert "[IO-414] don't write a BOM on every (or any) line (#492)"
This reverts commit 469ef76.
1 parent 914ca79 commit 43594ce

2 files changed

Lines changed: 2 additions & 20 deletions

File tree

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import java.nio.channels.ReadableByteChannel;
4646
import java.nio.channels.Selector;
4747
import java.nio.charset.Charset;
48-
import java.nio.charset.StandardCharsets;
4948
import java.nio.file.Files;
5049
import java.util.Arrays;
5150
import java.util.Collection;
@@ -3829,15 +3828,11 @@ public static void writeLines(final Collection<?> lines, final String lineEnding
38293828
* an {@link OutputStream} line by line, using the specified character
38303829
* encoding and the specified line ending.
38313830
*
3832-
* UTF-16 is written big-endian with no byte order mark.
3833-
* For little endian, use UTF-16LE. For a BOM, write it to the stream
3834-
* before calling this method.
3835-
*
38363831
* @param lines the lines to write, null entries produce blank lines
38373832
* @param lineEnding the line separator to use, null is system default
38383833
* @param output the {@link OutputStream} to write to, not null, not closed
38393834
* @param charset the charset to use, null means platform default
3840-
* @throws NullPointerException if output is null
3835+
* @throws NullPointerException if the output is null
38413836
* @throws IOException if an I/O error occurs
38423837
* @since 2.3
38433838
*/
@@ -3849,11 +3844,7 @@ public static void writeLines(final Collection<?> lines, String lineEnding, fina
38493844
if (lineEnding == null) {
38503845
lineEnding = System.lineSeparator();
38513846
}
3852-
Charset cs = Charsets.toCharset(charset);
3853-
// don't write a BOM
3854-
if (cs == StandardCharsets.UTF_16) {
3855-
cs = StandardCharsets.UTF_16BE;
3856-
}
3847+
final Charset cs = Charsets.toCharset(charset);
38573848
final byte[] eolBytes = lineEnding.getBytes(cs);
38583849
for (final Object line : lines) {
38593850
if (line != null) {

src/test/java/org/apache/commons/io/IOUtilsTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,13 +1761,4 @@ public void testWriteLittleString() throws IOException {
17611761
}
17621762
}
17631763

1764-
@Test
1765-
public void testWriteLines() throws IOException {
1766-
final String[] data = {"The", "quick"};
1767-
final ByteArrayOutputStream out = new ByteArrayOutputStream();
1768-
IOUtils.writeLines(Arrays.asList(data), "\n", out, "UTF-16");
1769-
final String result = new String(out.toByteArray(), StandardCharsets.UTF_16);
1770-
assertEquals("The\nquick\n", result);
1771-
}
1772-
17731764
}

0 commit comments

Comments
 (0)