groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Use `StringBuilderWriter` instead
Date Fri, 05 Jan 2018 05:35:39 GMT
Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_5_X d289798c2 -> 1db304518


Use `StringBuilderWriter` instead

(cherry picked from commit 3d4ab71)


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

Branch: refs/heads/GROOVY_2_5_X
Commit: 1db30451843f0dbf0da5ba161146d134aaef9a07
Parents: d289798
Author: sunlan <sunlan@apache.org>
Authored: Fri Jan 5 12:29:21 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Fri Jan 5 13:35:23 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/lang/Closure.java        |  4 ++--
 src/main/groovy/groovy/util/ConfigObject.java   |  6 +++---
 .../groovy/classgen/AsmClassGenerator.java      |  7 ++++---
 .../MultipleCompilationErrorsException.java     |  6 ++++--
 .../groovy/runtime/EncodingGroovyMethods.java   |  6 +++---
 .../groovy/runtime/IOGroovyMethods.java         |  4 ++--
 .../codehaus/groovy/runtime/InvokerHelper.java  |  4 ++--
 .../groovy/runtime/StringGroovyMethods.java     |  5 +++--
 .../org/codehaus/groovy/syntax/CSTNode.java     |  8 ++++----
 .../groovy/tools/javac/JavaStubGenerator.java   |  5 +++--
 .../groovy/tools/javac/JavacJavaCompiler.java   | 10 +++++-----
 .../transform/stc/SignatureCodecVersion1.java   |  5 +++--
 .../groovy/classgen/DumpingClassLoader.java     |  4 ++--
 .../codehaus/groovy/ant/CompileTaskSupport.java |  5 +++--
 .../java/org/codehaus/groovy/ant/Groovy.java    |  7 ++++---
 .../java/org/codehaus/groovy/ant/Groovyc.java   |  5 +++--
 .../org/codehaus/groovy/ant/GroovyTest.java     |  7 +++++--
 .../java/groovy/json/StringEscapeUtils.java     | 11 ++++++-----
 .../groovy/text/SimpleTemplateEngine.java       | 20 ++++++++++----------
 .../groovy/groovy/text/XmlTemplateEngine.java   |  6 +++---
 .../groovy/groovy/text/markup/BaseTemplate.java |  6 +++---
 .../src/main/java/groovy/xml/XmlUtil.java       | 10 +++++-----
 22 files changed, 82 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/groovy/groovy/lang/Closure.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Closure.java b/src/main/groovy/groovy/lang/Closure.java
index 99d2ea9..edac29f 100644
--- a/src/main/groovy/groovy/lang/Closure.java
+++ b/src/main/groovy/groovy/lang/Closure.java
@@ -19,6 +19,7 @@
 package groovy.lang;
 
 import org.apache.groovy.internal.util.UncheckedThrow;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.reflection.ReflectionCache;
 import org.codehaus.groovy.reflection.stdclasses.CachedClosureClass;
 import org.codehaus.groovy.runtime.ComposedClosure;
@@ -32,7 +33,6 @@ import org.codehaus.groovy.runtime.memoize.UnlimitedConcurrentCache;
 
 import java.io.IOException;
 import java.io.Serializable;
-import java.io.StringWriter;
 import java.io.Writer;
 
 /**
@@ -976,7 +976,7 @@ public abstract class Closure<V> extends GroovyObjectSupport implements
Cloneabl
          * @see java.lang.Object#toString()
          */
         public String toString() {
-            final StringWriter writer = new StringWriter();
+            final Writer writer = new StringBuilderWriter();
 
             try {
                 writeTo(writer);

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/groovy/groovy/util/ConfigObject.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/util/ConfigObject.java b/src/main/groovy/groovy/util/ConfigObject.java
index c76bc97..f17c36f 100644
--- a/src/main/groovy/groovy/util/ConfigObject.java
+++ b/src/main/groovy/groovy/util/ConfigObject.java
@@ -21,6 +21,7 @@ package groovy.util;
 import groovy.lang.GroovyObjectSupport;
 import groovy.lang.GroovyRuntimeException;
 import groovy.lang.Writable;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.runtime.DefaultGroovyMethods;
 import org.codehaus.groovy.runtime.InvokerHelper;
 import org.codehaus.groovy.runtime.StringGroovyMethods;
@@ -28,7 +29,6 @@ import org.codehaus.groovy.syntax.Types;
 
 import java.io.BufferedWriter;
 import java.io.IOException;
-import java.io.StringWriter;
 import java.io.Writer;
 import java.net.URL;
 import java.util.Collection;
@@ -401,7 +401,7 @@ public class ConfigObject extends GroovyObjectSupport implements Writable,
Map,
     }
 
     public String prettyPrint() {
-        StringWriter sw = new StringWriter();
+        Writer sw = new StringBuilderWriter();
         try {
             writeTo(sw);
         } catch (IOException e) {
@@ -413,7 +413,7 @@ public class ConfigObject extends GroovyObjectSupport implements Writable,
Map,
 
     @Override
     public String toString() {
-        StringWriter sw = new StringWriter();
+        Writer sw = new StringBuilderWriter();
         try {
             InvokerHelper.write(sw, this);
         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 5f73931..099bc9c 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -19,6 +19,7 @@
 package org.codehaus.groovy.classgen;
 
 import groovy.lang.GroovyRuntimeException;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.ast.ASTNode;
 import org.codehaus.groovy.ast.AnnotatedNode;
@@ -113,7 +114,7 @@ import org.objectweb.asm.Type;
 import org.objectweb.asm.util.TraceMethodVisitor;
 
 import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.io.Writer;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -425,10 +426,10 @@ public class AsmClassGenerator extends ClassGenerator {
             try {
                 mv.visitMaxs(0, 0);
             } catch (Exception e) {
-                StringWriter writer = null;
+                Writer writer = null;
                 if (mv instanceof TraceMethodVisitor) {
                     TraceMethodVisitor tracer = (TraceMethodVisitor) mv;
-                    writer = new StringWriter();
+                    writer = new StringBuilderWriter();
                     PrintWriter p = new PrintWriter(writer);
                     tracer.p.print(p);
                     p.flush();

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/control/MultipleCompilationErrorsException.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/control/MultipleCompilationErrorsException.java
b/src/main/java/org/codehaus/groovy/control/MultipleCompilationErrorsException.java
index 0d7dc3c..e53762e 100644
--- a/src/main/java/org/codehaus/groovy/control/MultipleCompilationErrorsException.java
+++ b/src/main/java/org/codehaus/groovy/control/MultipleCompilationErrorsException.java
@@ -18,8 +18,10 @@
  */
 package org.codehaus.groovy.control;
 
+import org.apache.groovy.io.StringBuilderWriter;
+
 import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.io.Writer;
 
 /**
  * @author Jochen Theodorou
@@ -46,7 +48,7 @@ public class MultipleCompilationErrorsException extends
     }
     
     public String getMessage() {
-        StringWriter data = new StringWriter();
+        Writer data = new StringBuilderWriter();
         PrintWriter writer = new PrintWriter(data);
         Janitor janitor = new Janitor();
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
index f8aeb49..44a312a 100644
--- a/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/EncodingGroovyMethods.java
@@ -20,10 +20,10 @@ package org.codehaus.groovy.runtime;
 
 import groovy.lang.StringWriterIOException;
 import groovy.lang.Writable;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
 
 import java.io.IOException;
-import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 
@@ -130,7 +130,7 @@ public class EncodingGroovyMethods {
             }
 
             public String toString() {
-                StringWriter buffer = new StringWriter();
+                Writer buffer = new StringBuilderWriter();
 
                 try {
                     writeTo(buffer);
@@ -329,7 +329,7 @@ public class EncodingGroovyMethods {
             }
 
             public String toString() {
-                StringWriter buffer = new StringWriter();
+                Writer buffer = new StringBuilderWriter();
 
                 try {
                     writeTo(buffer);

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
index f33d377..5fd2ef1 100644
--- a/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/IOGroovyMethods.java
@@ -27,6 +27,7 @@ import groovy.transform.stc.FirstParam;
 import groovy.transform.stc.FromString;
 import groovy.transform.stc.PickFirstResolver;
 import groovy.transform.stc.SimpleType;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.runtime.callsite.BooleanClosureWrapper;
 
 import java.io.BufferedReader;
@@ -45,7 +46,6 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.Reader;
-import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.nio.charset.Charset;
@@ -1505,7 +1505,7 @@ public class IOGroovyMethods extends DefaultGroovyMethodsSupport {
             }
 
             public String toString() {
-                StringWriter buffer = new StringWriter();
+                Writer buffer = new StringBuilderWriter();
                 try {
                     writeTo(buffer);
                 } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
index 890abf2..b518146 100644
--- a/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -35,6 +35,7 @@ import groovy.lang.SpreadMap;
 import groovy.lang.SpreadMapEvaluatingException;
 import groovy.lang.Tuple;
 import groovy.lang.Writable;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.control.ResolveVisitor;
 import org.codehaus.groovy.reflection.ClassInfo;
 import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl;
@@ -49,7 +50,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
-import java.io.StringWriter;
 import java.io.Writer;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
@@ -561,7 +561,7 @@ public class InvokerHelper {
             out.append(toListString((Collection) object));
         } else if (object instanceof Writable) {
             Writable writable = (Writable) object;
-            StringWriter stringWriter = new StringWriter();
+            Writer stringWriter = new StringBuilderWriter();
             writable.writeTo(stringWriter);
             out.append(stringWriter.toString());
         } else if (object instanceof InputStream || object instanceof Reader) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 4a8eafc..ba8f1bc 100644
--- a/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -27,13 +27,14 @@ import groovy.transform.stc.ClosureParams;
 import groovy.transform.stc.FromString;
 import groovy.transform.stc.PickFirstResolver;
 import groovy.transform.stc.SimpleType;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
 import org.codehaus.groovy.util.CharSequenceReader;
 
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.IOException;
-import java.io.StringWriter;
+import java.io.Writer;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.util.ArrayList;
@@ -416,7 +417,7 @@ public class StringGroovyMethods extends DefaultGroovyMethodsSupport {
         // Don't do this in static initializer because we may never be needed.
         // TODO: Put this lineSeparator property somewhere everyone can use it.
         if (lineSeparator == null) {
-            final StringWriter sw = new StringWriter(2);
+            final Writer sw = new StringBuilderWriter(2);
             try {
                 // We use BufferedWriter rather than System.getProperty because
                 // it has the security manager rigamarole to deal with the possible exception.

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/syntax/CSTNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/syntax/CSTNode.java b/src/main/java/org/codehaus/groovy/syntax/CSTNode.java
index d23c2cd..d239190 100644
--- a/src/main/java/org/codehaus/groovy/syntax/CSTNode.java
+++ b/src/main/java/org/codehaus/groovy/syntax/CSTNode.java
@@ -18,10 +18,11 @@
  */
 package org.codehaus.groovy.syntax;
 
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.GroovyBugError;
 
 import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.io.Writer;
 
 
 /**
@@ -476,10 +477,9 @@ public abstract class CSTNode
 
     public String toString()
     {
-        StringWriter string = new StringWriter();
-        write( new PrintWriter(string) );
+        Writer string = new StringBuilderWriter();
+        write(new PrintWriter(string));
 
-        string.flush();
         return string.toString();
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index f8df25e..c5c6360 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -18,6 +18,7 @@
  */
 package org.codehaus.groovy.tools.javac;
 
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.ast.AnnotatedNode;
 import org.codehaus.groovy.ast.AnnotationNode;
 import org.codehaus.groovy.ast.ClassHelper;
@@ -56,7 +57,7 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.io.Writer;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -878,7 +879,7 @@ public class JavaStubGenerator {
             ConstantExpression ce = (ConstantExpression) memberValue;
             Object constValue = ce.getValue();
             if (constValue instanceof AnnotationNode) {
-                StringWriter writer = new StringWriter();
+                Writer writer = new StringBuilderWriter();
                 PrintWriter out = new PrintWriter(writer);
                 printAnnotation(out, (AnnotationNode) constValue);
                 val = writer.toString();

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java b/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
index 4c8039d..a705ecf 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
@@ -20,6 +20,7 @@ package org.codehaus.groovy.tools.javac;
 
 import groovy.lang.GroovyClassLoader;
 import groovy.lang.GroovyObject;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.control.CompilationUnit;
 import org.codehaus.groovy.control.CompilerConfiguration;
 import org.codehaus.groovy.control.messages.ExceptionMessage;
@@ -28,7 +29,6 @@ import org.codehaus.groovy.runtime.DefaultGroovyMethods;
 
 import java.io.File;
 import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.URISyntaxException;
@@ -52,14 +52,14 @@ public class JavacJavaCompiler implements JavaCompiler {
 
     public void compile(List<String> files, CompilationUnit cu) {
         String[] javacParameters = makeParameters(files, cu.getClassLoader());
-        StringWriter javacOutput = null;
+        StringBuilderWriter javacOutput = null;
         int javacReturnValue = 0;
         try {
             Class javac = findJavac(cu);
             Method method = null;
             try {
                 method = javac.getMethod("compile", new Class[]{String[].class, PrintWriter.class});
-                javacOutput = new StringWriter();
+                javacOutput = new StringBuilderWriter();
                 PrintWriter writer = new PrintWriter(javacOutput);
                 Object ret = method.invoke(null, javacParameters, writer);
                 javacReturnValue = (Integer) ret;
@@ -88,9 +88,9 @@ public class JavacJavaCompiler implements JavaCompiler {
         }
     }
 
-    private static void addJavacError(String header, CompilationUnit cu, StringWriter msg)
{
+    private static void addJavacError(String header, CompilationUnit cu, StringBuilderWriter
msg) {
         if (msg != null) {
-            header = header + "\n" + msg.getBuffer().toString();
+            header = header + "\n" + msg.getBuilder().toString();
         } else {
             header = header +
                     "\nThis javac version does not support compile(String[],PrintWriter),
" +

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/main/java/org/codehaus/groovy/transform/stc/SignatureCodecVersion1.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/SignatureCodecVersion1.java b/src/main/java/org/codehaus/groovy/transform/stc/SignatureCodecVersion1.java
index d367e17..6cb512f 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/SignatureCodecVersion1.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/SignatureCodecVersion1.java
@@ -19,6 +19,7 @@
 package org.codehaus.groovy.transform.stc;
 
 import groovy.lang.GroovyRuntimeException;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.ast.ClassHelper;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.GenericsType;
@@ -31,7 +32,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
-import java.io.StringWriter;
+import java.io.Writer;
 
 import static org.codehaus.groovy.ast.ClassHelper.OBJECT_TYPE;
 import static org.codehaus.groovy.ast.ClassHelper.VOID_TYPE;
@@ -122,7 +123,7 @@ public class SignatureCodecVersion1 implements SignatureCodec {
     public String encode(final ClassNode node) {
         ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
         DataOutputStream dos = new DataOutputStream(baos);
-        StringWriter wrt = new StringWriter();
+        Writer wrt = new StringBuilderWriter();
         String encoded = null;
         try {
             doEncode(node, dos);

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/src/test/org/codehaus/groovy/classgen/DumpingClassLoader.java
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/classgen/DumpingClassLoader.java b/src/test/org/codehaus/groovy/classgen/DumpingClassLoader.java
index 79fcffb..a7e61de 100644
--- a/src/test/org/codehaus/groovy/classgen/DumpingClassLoader.java
+++ b/src/test/org/codehaus/groovy/classgen/DumpingClassLoader.java
@@ -19,6 +19,7 @@
 package org.codehaus.groovy.classgen;
 
 import groovy.lang.GroovyClassLoader;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.ast.ClassNode;
 import org.codehaus.groovy.ast.CompileUnit;
 import org.codehaus.groovy.control.CompilationUnit;
@@ -32,7 +33,6 @@ import org.objectweb.asm.util.TraceClassVisitor;
 
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
-import java.io.StringWriter;
 
 /**
  * A class loader used for debugging the bytecode generation.
@@ -75,7 +75,7 @@ public class DumpingClassLoader extends GroovyClassLoader implements Opcodes
{
     }
 
     protected TraceClassVisitor dumpVisitor = new TraceClassVisitor(null, new ASMifier(),
new PrintWriter(new OutputStreamWriter(System.out)));
-    protected TraceClassVisitor invisibleDumpVisitor = new TraceClassVisitor(null, new ASMifier(),
new PrintWriter(new StringWriter()));
+    protected TraceClassVisitor invisibleDumpVisitor = new TraceClassVisitor(null, new ASMifier(),
new PrintWriter(new StringBuilderWriter()));
     protected CompileUnit unit = new CompileUnit(this, new CompilerConfiguration());
     protected ClassGenerator checker =
             new AsmClassGenerator(null,new GeneratorContext(unit), new CheckClassAdapter(invisibleDumpVisitor),
null);

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
index cf80813..e7e9025 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/CompileTaskSupport.java
@@ -19,6 +19,7 @@
 package org.codehaus.groovy.ant;
 
 import groovy.lang.GroovyClassLoader;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.MatchingTask;
 import org.apache.tools.ant.types.Path;
@@ -28,7 +29,7 @@ import org.codehaus.groovy.tools.ErrorReporter;
 
 import java.io.File;
 import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.io.Writer;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
@@ -160,7 +161,7 @@ public abstract class CompileTaskSupport
     protected void handleException(final Exception e) throws BuildException {
         assert e != null;
         
-        StringWriter writer = new StringWriter();
+        Writer writer = new StringBuilderWriter();
         new ErrorReporter(e, false).write(new PrintWriter(writer));
         String message = writer.toString();
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
index 38ac0b3..d54e575 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovy.java
@@ -24,6 +24,7 @@ import groovy.lang.GroovyShell;
 import groovy.lang.MissingMethodException;
 import groovy.lang.Script;
 import groovy.util.AntBuilder;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.Java;
@@ -48,7 +49,7 @@ import java.io.IOException;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.io.Reader;
-import java.io.StringWriter;
+import java.io.Writer;
 import java.lang.reflect.Field;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -407,7 +408,7 @@ public class Groovy extends Java {
                 configureCompiler();
                 super.execute();
             } catch (Exception e) {
-                StringWriter writer = new StringWriter();
+                Writer writer = new StringBuilderWriter();
                 new ErrorReporter(e, false).write(new PrintWriter(writer));
                 String message = writer.toString();
                 throw new BuildException("Script Failed: " + message, e, getLocation());
@@ -535,7 +536,7 @@ public class Groovy extends Java {
     }
 
     private void processError(Exception e) {
-        StringWriter writer = new StringWriter();
+        Writer writer = new StringBuilderWriter();
         new ErrorReporter(e, false).write(new PrintWriter(writer));
         String message = writer.toString();
         throw new BuildException("Script Failed: " + message, e, getLocation());

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index c2e0641..224f37c 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -24,6 +24,7 @@ import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.DefaultParser;
 import org.apache.commons.cli.Options;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.apache.tools.ant.AntClassLoader;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
@@ -49,7 +50,7 @@ import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.io.Writer;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.nio.charset.Charset;
@@ -1217,7 +1218,7 @@ public class Groovyc extends MatchingTask {
                 // unwrap to the real exception
                 t = re.getCause();
             }
-            StringWriter writer = new StringWriter();
+            Writer writer = new StringBuilderWriter();
             new ErrorReporter(t, false).write(new PrintWriter(writer));
             String message = writer.toString();
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovyTest.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovyTest.java
b/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovyTest.java
index 39a818a..53c0e86 100644
--- a/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovyTest.java
+++ b/subprojects/groovy-ant/src/test/groovy/org/codehaus/groovy/ant/GroovyTest.java
@@ -22,11 +22,14 @@ import groovy.lang.GroovyRuntimeException;
 import groovy.util.GroovyTestCase;
 import junit.framework.Test;
 import junit.framework.TestSuite;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectHelper;
 
-import java.io.*;
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.Writer;
 import java.util.regex.Pattern;
 
 /**
@@ -148,7 +151,7 @@ public class GroovyTest extends GroovyTestCase {
             final Throwable cause = e.getCause();
             assertTrue(cause instanceof GroovyRuntimeException);
 
-            final StringWriter sw = new StringWriter();
+            final Writer sw = new StringBuilderWriter();
             cause.printStackTrace(new PrintWriter(sw));
             
             final String stackTrace = sw.toString();

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/subprojects/groovy-json/src/main/java/groovy/json/StringEscapeUtils.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-json/src/main/java/groovy/json/StringEscapeUtils.java b/subprojects/groovy-json/src/main/java/groovy/json/StringEscapeUtils.java
index d6ef683..059c5a1 100644
--- a/subprojects/groovy-json/src/main/java/groovy/json/StringEscapeUtils.java
+++ b/subprojects/groovy-json/src/main/java/groovy/json/StringEscapeUtils.java
@@ -18,8 +18,9 @@
  */
 package groovy.json;
 
+import org.apache.groovy.io.StringBuilderWriter;
+
 import java.io.IOException;
-import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Locale;
 
@@ -153,11 +154,11 @@ public class StringEscapeUtils {
             return null;
         }
         try {
-            StringWriter writer = new StringWriter(str.length() * 2);
+            Writer writer = new StringBuilderWriter(str.length() * 2);
             escapeJavaStyleString(writer, str, escapeSingleQuotes, escapeForwardSlash);
             return writer.toString();
         } catch (IOException ioe) {
-            // this should never ever happen while writing to a StringWriter
+            // this should never ever happen while writing to a StringBuilderWriter
             throw new RuntimeException(ioe);
         }
     }
@@ -276,11 +277,11 @@ public class StringEscapeUtils {
             return null;
         }
         try {
-            StringWriter writer = new StringWriter(str.length());
+            Writer writer = new StringBuilderWriter(str.length());
             unescapeJava(writer, str);
             return writer.toString();
         } catch (IOException ioe) {
-            // this should never ever happen while writing to a StringWriter
+            // this should never ever happen while writing to a StringBuilderWriter
             throw new RuntimeException(ioe);
         }
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
b/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
index f9dd80c..e4776ab 100644
--- a/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
+++ b/subprojects/groovy-templates/src/main/groovy/groovy/text/SimpleTemplateEngine.java
@@ -23,6 +23,7 @@ import groovy.lang.GroovyRuntimeException;
 import groovy.lang.GroovyShell;
 import groovy.lang.Script;
 import groovy.lang.Writable;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.control.CompilationFailedException;
 import org.codehaus.groovy.runtime.InvokerHelper;
 
@@ -30,7 +31,6 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.Reader;
-import java.io.StringWriter;
 import java.io.Writer;
 import java.util.Map;
 
@@ -179,7 +179,7 @@ public class SimpleTemplateEngine extends TemplateEngine {
                  * @see java.lang.Object#toString()
                  */
                 public String toString() {
-                    StringWriter sw = new StringWriter();
+                    Writer sw = new StringBuilderWriter();
                     writeTo(sw);
                     return sw.toString();
                 }
@@ -198,7 +198,7 @@ public class SimpleTemplateEngine extends TemplateEngine {
             if (!reader.markSupported()) {
                 reader = new BufferedReader(reader);
             }
-            StringWriter sw = new StringWriter();
+            StringBuilderWriter sw = new StringBuilderWriter();
             startScript(sw);
             int c;
             while ((c = reader.read()) != -1) {
@@ -256,16 +256,16 @@ public class SimpleTemplateEngine extends TemplateEngine {
             return sw.toString();
         }
 
-        private void startScript(StringWriter sw) {
+        private void startScript(StringBuilderWriter sw) {
             sw.write("out.print(\"\"\"");
         }
 
-        private void endScript(StringWriter sw) {
+        private void endScript(StringBuilderWriter sw) {
             sw.write("\"\"\");\n");
             sw.write("\n/* Generated by SimpleTemplateEngine */");
         }
 
-        private void processGSstring(Reader reader, StringWriter sw) throws IOException {
+        private void processGSstring(Reader reader, StringBuilderWriter sw) throws IOException
{
             int c;
             while ((c = reader.read()) != -1) {
                 if (c != '\n' && c != '\r') {
@@ -281,10 +281,10 @@ public class SimpleTemplateEngine extends TemplateEngine {
          * Closes the currently open write and writes out the following text as a GString
expression until it reaches an end %>.
          *
          * @param reader a reader for the template text
-         * @param sw     a StringWriter to write expression content
+         * @param sw     a StringBuilderWriter to write expression content
          * @throws IOException if something goes wrong
          */
-        private void groovyExpression(Reader reader, StringWriter sw) throws IOException
{
+        private void groovyExpression(Reader reader, StringBuilderWriter sw) throws IOException
{
             sw.write("${");
             int c;
             while ((c = reader.read()) != -1) {
@@ -307,10 +307,10 @@ public class SimpleTemplateEngine extends TemplateEngine {
          * Closes the currently open write and writes the following text as normal Groovy
script code until it reaches an end %>.
          *
          * @param reader a reader for the template text
-         * @param sw     a StringWriter to write expression content
+         * @param sw     a StringBuilderWriter to write expression content
          * @throws IOException if something goes wrong
          */
-        private void groovySection(Reader reader, StringWriter sw) throws IOException {
+        private void groovySection(Reader reader, StringBuilderWriter sw) throws IOException
{
             sw.write("\"\"\");");
             int c;
             while ((c = reader.read()) != -1) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/subprojects/groovy-templates/src/main/groovy/groovy/text/XmlTemplateEngine.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-templates/src/main/groovy/groovy/text/XmlTemplateEngine.java
b/subprojects/groovy-templates/src/main/groovy/groovy/text/XmlTemplateEngine.java
index 2d8d042..e463770 100644
--- a/subprojects/groovy-templates/src/main/groovy/groovy/text/XmlTemplateEngine.java
+++ b/subprojects/groovy-templates/src/main/groovy/groovy/text/XmlTemplateEngine.java
@@ -28,6 +28,7 @@ import groovy.util.Node;
 import groovy.util.XmlNodePrinter;
 import groovy.util.XmlParser;
 import groovy.xml.QName;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.control.CompilationFailedException;
 import org.codehaus.groovy.runtime.InvokerHelper;
 import org.xml.sax.SAXException;
@@ -36,7 +37,6 @@ import javax.xml.parsers.ParserConfigurationException;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.Reader;
-import java.io.StringWriter;
 import java.io.Writer;
 import java.lang.ref.WeakReference;
 import java.util.HashMap;
@@ -261,7 +261,7 @@ public class XmlTemplateEngine extends TemplateEngine {
             if (result.get() != null) {
                 return result.get().toString();
             }
-            String string = writeTo(new StringWriter(1024)).toString();
+            String string = writeTo(new StringBuilderWriter(1024)).toString();
             result = new WeakReference(string);
             return string;
         }
@@ -305,7 +305,7 @@ public class XmlTemplateEngine extends TemplateEngine {
             throw new IOException("Parsing XML source failed: root node is null.");
         }
 
-        StringWriter writer = new StringWriter(1024);
+        StringBuilderWriter writer = new StringBuilderWriter(1024);
         writer.write("/* Generated by XmlTemplateEngine */\n");
         new GspPrinter(new PrintWriter(writer), indentation).print(root);
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
index 20121c9..02ed5c6 100644
--- a/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
+++ b/subprojects/groovy-templates/src/main/groovy/groovy/text/markup/BaseTemplate.java
@@ -22,12 +22,12 @@ import groovy.lang.Closure;
 import groovy.lang.Writable;
 import groovy.text.Template;
 import org.apache.groovy.internal.util.UncheckedThrow;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.control.io.NullWriter;
 import org.codehaus.groovy.runtime.ResourceGroovyMethods;
 
 import java.io.IOException;
 import java.io.StringReader;
-import java.io.StringWriter;
 import java.io.Writer;
 import java.net.URL;
 import java.util.Collections;
@@ -107,7 +107,7 @@ public abstract class BaseTemplate implements Writable {
 
     public String stringOf(Closure cl) throws IOException {
         Writer old = out;
-        StringWriter stringWriter = new StringWriter(32);
+        Writer stringWriter = new StringBuilderWriter(32);
         out = stringWriter;
         Object result = cl.call();
         if (result!=null && result!=this) {
@@ -514,7 +514,7 @@ public abstract class BaseTemplate implements Writable {
     }
 
     public String toString() {
-        StringWriter wrt = new StringWriter(512);
+        Writer wrt = new StringBuilderWriter(512);
         try {
             writeTo(wrt);
         } catch (IOException e) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/1db30451/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
index 4867f51..fcdabcc 100644
--- a/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
+++ b/subprojects/groovy-xml/src/main/java/groovy/xml/XmlUtil.java
@@ -24,6 +24,7 @@ import groovy.lang.Writable;
 import groovy.util.Node;
 import groovy.util.XmlNodePrinter;
 import groovy.util.slurpersupport.GPathResult;
+import org.apache.groovy.io.StringBuilderWriter;
 import org.codehaus.groovy.runtime.InvokerHelper;
 import org.codehaus.groovy.runtime.StringGroovyMethods;
 import org.w3c.dom.Element;
@@ -48,7 +49,6 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.StringReader;
-import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.net.URL;
@@ -66,7 +66,7 @@ public class XmlUtil {
      * @return the pretty String representation of the Element
      */
     public static String serialize(Element element) {
-        StringWriter sw = new StringWriter();
+        Writer sw = new StringBuilderWriter();
         serialize(new DOMSource(element), sw);
         return sw.toString();
     }
@@ -190,7 +190,7 @@ public class XmlUtil {
      * @return the pretty String representation of the original content
      */
     public static String serialize(String xmlString) {
-        StringWriter sw = new StringWriter();
+        Writer sw = new StringBuilderWriter();
         serialize(asStreamSource(xmlString), sw);
         return sw.toString();
     }
@@ -400,7 +400,7 @@ public class XmlUtil {
     }
 
     private static String asString(Node node) {
-        StringWriter sw = new StringWriter();
+        Writer sw = new StringBuilderWriter();
         PrintWriter pw = new PrintWriter(sw);
         XmlNodePrinter nodePrinter = new XmlNodePrinter(pw);
         nodePrinter.setPreserveWhitespace(true);
@@ -426,7 +426,7 @@ public class XmlUtil {
         if (writable instanceof GPathResult) {
             return asString((GPathResult) writable); //GROOVY-4285
         }
-        Writer sw = new StringWriter();
+        Writer sw = new StringBuilderWriter();
         try {
             writable.writeTo(sw);
         } catch (IOException e) {


Mime
View raw message