You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Florent Brosse (JIRA)" <ji...@apache.org> on 2013/12/08 17:40:35 UTC
[jira] [Commented] (IO-414) IOUtils.writeLines is not correct with
a charset with BOM
[ https://issues.apache.org/jira/browse/IO-414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13842551#comment-13842551 ]
Florent Brosse commented on IO-414:
-----------------------------------
I propose that code to correct that bug:
public static void writeLines(final Collection<?> lines, String lineEnding, final OutputStream output, final Charset encoding)
throws IOException {
if (lines == null) {
return;
}
if (lineEnding == null) {
lineEnding = LINE_SEPARATOR;
}
final Charset cs = Charsets.toCharset(encoding);
StringBuilder stringBuilder = new StringBuilder();
for (final Object line : lines) {
if (line != null) {
stringBuilder.append(line.toString());
}
stringBuilder.append(lineEnding);
}
output.write(stringBuilder.toString().getBytes(cs));
}
public static void writeLines(final Collection<?> lines, String lineEnding,
final Writer writer) throws IOException {
if (lines == null) {
return;
}
if (lineEnding == null) {
lineEnding = LINE_SEPARATOR;
}
StringBuilder stringBuilder = new StringBuilder();
for (final Object line : lines) {
if (line != null) {
stringBuilder.append(line.toString());
}
stringBuilder.append(lineEnding);
}
writer.write(stringBuilder.toString());
}
> IOUtils.writeLines is not correct with a charset with BOM
> ---------------------------------------------------------
>
> Key: IO-414
> URL: https://issues.apache.org/jira/browse/IO-414
> Project: Commons IO
> Issue Type: Bug
> Components: Streams/Writers, Utilities
> Affects Versions: 2.4, 2.5
> Reporter: Florent Brosse
>
> When a charset has a BOM (like UTF-16), the method IOUtils.writeLines put 2 BOM on each line.
--
This message was sent by Atlassian JIRA
(v6.1#6144)