Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3852010BA2 for ; Sun, 8 Dec 2013 16:44:39 +0000 (UTC) Received: (qmail 93349 invoked by uid 500); 8 Dec 2013 16:44:37 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 93002 invoked by uid 500); 8 Dec 2013 16:44:36 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 92994 invoked by uid 99); 8 Dec 2013 16:44:35 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Dec 2013 16:44:35 +0000 Date: Sun, 8 Dec 2013 16:44:35 +0000 (UTC) From: "Florent Brosse (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (IO-414) IOUtils.writeLines is not correct with a charset with BOM MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/IO-414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13842551#comment-13842551 ] Florent Brosse edited comment on IO-414 at 12/8/13 4:43 PM: ------------------------------------------------------------ I suggest 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()); } was (Author: florent.brosse): 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)