Bug 185998 - Allow OutputStream alternative to StringBuffer.
Summary: Allow OutputStream alternative to StringBuffer.
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Jet (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Paul Elder CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-08 14:05 EDT by bungeman CLA
Modified: 2020-05-01 16:11 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bungeman CLA 2007-05-08 14:05:56 EDT
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.
Comment 1 Paul Elder CLA 2007-05-23 13:14:47 EDT
I will consider this as we enter planning for the next (Jun 2008) release. Changing to an enhancement.
Comment 2 Stephen Crawley CLA 2008-02-05 20:59:54 EST
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.
Comment 3 Paul Elder CLA 2008-02-06 08:44:08 EST
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.
Comment 4 Fabrice Daugan CLA 2009-11-22 11:34:23 EST
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"
Comment 5 Fabrice Daugan CLA 2009-11-22 11:41:16 EST
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"