You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by ke...@apache.org on 2015/08/20 03:10:27 UTC

incubator-groovy git commit: GROOVY-7553: Path.write() appends when encoding parameter present (closes #89)

Repository: incubator-groovy
Updated Branches:
  refs/heads/master 1f50866cc -> ab9a8f226


GROOVY-7553: Path.write() appends when encoding parameter present (closes #89)


Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/ab9a8f22
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/ab9a8f22
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/ab9a8f22

Branch: refs/heads/master
Commit: ab9a8f22637d3805a96008063b1dc6c533c2b001
Parents: 1f50866
Author: Keegan Witt <ke...@gmail.com>
Authored: Wed Aug 19 11:17:31 2015 -0400
Committer: Keegan Witt <ke...@gmail.com>
Committed: Wed Aug 19 21:09:18 2015 -0400

----------------------------------------------------------------------
 .../org/codehaus/groovy/runtime/NioGroovyMethods.java    |  2 +-
 .../codehaus/groovy/runtime/NioGroovyMethodsTest.groovy  | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/ab9a8f22/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java b/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
index 029084d..8c9271f 100644
--- a/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
+++ b/subprojects/groovy-nio/src/main/java/org/codehaus/groovy/runtime/NioGroovyMethods.java
@@ -559,7 +559,7 @@ public class NioGroovyMethods extends DefaultGroovyMethodsSupport {
     public static void write(Path self, String text, String charset) throws IOException {
         Writer writer = null;
         try {
-            writer = new OutputStreamWriter(Files.newOutputStream(self, CREATE, APPEND), Charset.forName(charset));
+            writer = new OutputStreamWriter(Files.newOutputStream(self), Charset.forName(charset));
             writer.write(text);
             writer.flush();
 

http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/ab9a8f22/subprojects/groovy-nio/src/test/groovy/org/codehaus/groovy/runtime/NioGroovyMethodsTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-nio/src/test/groovy/org/codehaus/groovy/runtime/NioGroovyMethodsTest.groovy b/subprojects/groovy-nio/src/test/groovy/org/codehaus/groovy/runtime/NioGroovyMethodsTest.groovy
index fe01a0e..7ec7d36 100644
--- a/subprojects/groovy-nio/src/test/groovy/org/codehaus/groovy/runtime/NioGroovyMethodsTest.groovy
+++ b/subprojects/groovy-nio/src/test/groovy/org/codehaus/groovy/runtime/NioGroovyMethodsTest.groovy
@@ -168,6 +168,17 @@ class NioGroovyMethodsTest extends Specification {
         file.text == 'Hello world!'
     }
 
+    def testWriteWithEncoding()  {
+        when:
+        def str = 'Hello world!'
+        def file = temporaryFolder.newFile()
+        file.toPath().write('Ciao mundo!')
+        file.toPath().write(str, 'UTF-8')
+
+        then:
+        file.text == str
+    }
+
     def testAppendObject() {
         setup:
         def file = temporaryFolder.newFile()