A PrinftTool comes in handy.  I've one I wish to donate
-------------------------------------------------------

                 Key: VELTOOLS-109
                 URL: https://issues.apache.org/jira/browse/VELTOOLS-109
             Project: Velocity Tools
          Issue Type: Improvement
          Components: GenericTools
    Affects Versions: 1.4, 2.0
         Environment: JDK 1.5, 6
            Reporter: Ezra Epstein
            Priority: Minor
             Fix For: 2.0, 1.4


import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;

public class PrintfTool extends org.apache.velocity.tools.generic.LocaleConfig {

                StringWriter output;
                PrintWriter printer;

                public PrintfTool() {
                        output = new StringWriter();
                        printer = new PrintWriter(output);
                }

                // Velocity doesn't support invoking with varargs
                private String printf(String format, Object... args) {
                        printer.printf(format, args);
                        printer.flush();
                        output.flush();
                        String result = output.toString();
                        output.getBuffer().setLength(0);
                        return result;
                }

                // Velocity does support invoking with a List of values.
                public String printf(String format, List args) {
                        return printf(format, args.toArray());
                }

                // Since value convenience method
                public String printf(String format, Object arg) {
                        return printf(format, new Object[] { arg });
                }

}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to