Return-Path: X-Original-To: apmail-groovy-notifications-archive@minotaur.apache.org Delivered-To: apmail-groovy-notifications-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 433E918975 for ; Sun, 5 Jul 2015 18:01:28 +0000 (UTC) Received: (qmail 2318 invoked by uid 500); 5 Jul 2015 18:01:28 -0000 Delivered-To: apmail-groovy-notifications-archive@groovy.apache.org Received: (qmail 2291 invoked by uid 500); 5 Jul 2015 18:01:28 -0000 Mailing-List: contact notifications-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.incubator.apache.org Delivered-To: mailing list notifications@groovy.incubator.apache.org Received: (qmail 2281 invoked by uid 99); 5 Jul 2015 18:01:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Jul 2015 18:01:28 +0000 X-ASF-Spam-Status: No, hits=-2000.6 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 05 Jul 2015 17:59:18 +0000 Received: (qmail 2255 invoked by uid 99); 5 Jul 2015 18:01:04 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Jul 2015 18:01:04 +0000 Date: Sun, 5 Jul 2015 18:01:04 +0000 (UTC) From: "Keegan Witt (JIRA)" To: notifications@groovy.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (GROOVY-7465) ResourceGroovyMethods/NioGroovyMethods BOM behavior is inconsistant MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/GROOVY-7465?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14614339#comment-14614339 ] Keegan Witt commented on GROOVY-7465: ------------------------------------- What should I put in the {{@Since}} tag? {{1.4.5}}? > ResourceGroovyMethods/NioGroovyMethods BOM behavior is inconsistant > ------------------------------------------------------------------- > > Key: GROOVY-7465 > URL: https://issues.apache.org/jira/browse/GROOVY-7465 > Project: Groovy > Issue Type: Bug > Components: groovy-jdk > Reporter: Keegan Witt > Assignee: Guillaume Laforge > > Most users would expect {{withPrintWriter}} to be a convenience method that behaves the same as if they had called {{new PrintWriter}} themselves, but this is not the current behavior: > {code:java} > File file = new File("tmp.txt") > try { > String text = " " > String charset = "UTF-16LE" > file.withPrintWriter(charset) { it << text } > println "withPrintWriter" > file.getBytes().each { System.out.format("%02x ", it) } > PrintWriter w = new PrintWriter(file, charset) > w.print(text) > w.close() > println "\n\nnew PrintWriter" > file.getBytes().each { System.out.format("%02x ", it) } > } finally { > file.delete() > } > {code} > Outputs > {noformat} > withPrintWriter > ff fe 20 00 > new PrintWriter > 20 00 > {noformat} > Additionally most users would expect that there's no difference in behavior between NIO and traditional methods, but this is also not the case > {code:java} > import java.nio.file.Files > import java.nio.file.FileSystems > import java.nio.file.Path > File file = new File("tmp1.txt") > Path path = FileSystems.getDefault().getPath("tmp2.txt") > try { > String text = " " > String charset = "UTF-16LE" > file.withPrintWriter(charset) { it << text } > println "withPrintWriter" > file.getBytes().each { System.out.format("%02x ", it) } > path.withPrintWriter(charset) { it << text } > println "\n\nnio withPrintWriter" > path.getBytes().each { System.out.format("%02x ", it) } > } finally { > file.delete() > Files.delete(path) > } > {code} > outputs > {noformat} > withPrintWriter > ff fe 20 00 > nio withPrintWriter > 20 00 > {noformat} > This is because {{ResourceGroovyMethods}} have a {{writeUTF16BomIfRequired}} method that {{NioGroovyMethods}} don't. > Most likely we'd want to change {{ResourceGroovyMethods}} to not add the BOM by default, or at least allow the user to opt out of that behavior by doing something like adding a boolean argument to the existing methods that would control that behavior. The other option would be to make the NIO methods consistent by having them also use {{writeUTF16BomIfRequired}}. > This began as a [discussion|http://mail-archives.apache.org/mod_mbox/incubator-groovy-users/201506.mbox/browser] on the user mailing list. -- This message was sent by Atlassian JIRA (v6.3.4#6332)