/*
 * Copyright 2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package groovy.io;

import java.io.File;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;

import org.codehaus.groovy.runtime.InvokerHelper;

/**
 * A PrintWriter that outputs objects in Groovy style.
 * That means print(Object) uses InvokerHelper.toString(Object)
 * to produce the same results as Writer.print(Object).
 *
 * @author Jim White
 */
public class GroovyPrintWriter extends PrintWriter 
{
    public GroovyPrintWriter(File file) throws FileNotFoundException
    {
        super(file);
    }

    public GroovyPrintWriter(File file, String csn)
        throws FileNotFoundException, UnsupportedEncodingException
    {
        super(file, csn);
    }

    public GroovyPrintWriter(Writer out) 
    {
        super(out);
    }

    public GroovyPrintWriter(Writer out, boolean autoflush) 
    {
        super(out, autoflush);
    }

    public GroovyPrintWriter(OutputStream out) 
    {
        super(out);
    }

    public GroovyPrintWriter(OutputStream out, boolean autoflush) 
    {
        super(out, autoflush);
    }

    public GroovyPrintWriter(String filename) throws FileNotFoundException 
    {
        super(filename);
    }

    public GroovyPrintWriter(String filename, String csn)
        throws FileNotFoundException, UnsupportedEncodingException 
    {
        super(filename, csn);
    }
        
// Don't need to do this if Groovy is going to print char[] like a string.
//    public void print(char[] x) 
//    {
//        super.write(InvokerHelper.toString(x));
//    }

    public void print(Object x) 
    {
        super.write(InvokerHelper.toString(x));
    }
}

@@ -2169,38 +2169,32 @@
     %7B%0A//        
-super.
 write(InvokerHel
@@ -2211,16 +2211,16 @@
 ng(x));%0A
+
 //    %7D%0A
@@ -2271,19 +2271,397 @@
     
-super.write
+write(InvokerHelper.toString(x));%0A    %7D%0A%0A    public void println(Object x) %0A    %7B%0A        // JDK 1.6 has changed the implementation to do a%0A        // String.valueOf(x) rather than call print(x).%0A        // Probably to improve performance by doing the conversion outside the lock.%0A        // This will do the same thing for us, and we don't have to have access to the lock.%0A        println
 (Inv

Fix breakage with JDK 1.6. They changed PrintWriter.println(Object) to not call PrintWriter.print(Object) anymore.