Community
Participate
Working Groups
When a template generator (XXXTemplate.java) is generated from a jet template file, the method which does the generation is "String generate(args)". The returned string is built up using a StringBuffer. This is ok, but it would be very nice to be able to specify an option which would generate a "void generate(PrintWriter out, args)" which would use the PrintWriter passed in rather than a StringBuffer. This would allow for clean producer/consumer usage of the generate method, such as allowing a PipedOutputStream based PrintWriter to be passed in to generate and a PipedInputStream on the other end to consume the output directly.
I will consider this as we enter planning for the next (Jun 2008) release. Changing to an enhancement.
As an aside, wouldn't it be a better idea to use a StringBuilder instead of aStringBuffer? This would avoid the overhead of locking on each append method call.
I will consider using StringBuilder. Up til now, I have resisted requiring Java 5 unless there was a compelling reason to leave the Java 1.4 community behind (there are still a few a few out there). One possibility is to provide two implementations, a StringBuffer-based one for Java 1.4 and a StringBuilder implementation for Java 5 and later.
It would be nice to configure the implementation to use. This way the default can still be StrinBuffer (1.4 compatible). Appendable implementation can be : BufferedWriter, StringBuffer, StringBuilder. Also, - the method to use must be given : "append", "write" and requires to exist in the given class and must have only one String.class parameter. - any additional constructor parameter must be provided. So default is : java.lang.StringBuffer and associated method is "append" But it could be : java.lang.StringBuilderand associated method is "append" But it could be : java.io.BufferedWriter and associated method is "write"