Forums Register Login

Unexpected characters using PrintWriter

+Pie Number of slices to send: Send
Hi, I am using Velocity to generate a script file, the script file producted however contains an extraneous last line as follows:

'java.io.PrintWriter@5f805f80'

The code is:

private void createDSJython(){
try{
//build Jython
VelocityEngine ve = new VelocityEngine();
ve.init();
VelocityContext context = new VelocityContext();
context.put("jndiName", dsAttrs);
Template t = ve.getTemplate( "testDs.vm" );
/* now render the template into a Writer */

BufferedWriter output = null;
File file = new File("D://createDs.py");
FileWriter fl = new FileWriter(file);
output = new BufferedWriter(fl);
PrintWriter print = new PrintWriter(output);
t.merge(context, print);
print.write(print.toString());

if (print != null) {
print.flush();
print.close();
}
}catch(Exception e){
e.printStackTrace();
}
}

and the Velocity templat, 'testDs.vm' is:

#foreach( $jndiName in $jndiName )
AdminTask.createDatasource(newjdbc, '[-name "ValidSystems DataSource" -jndiName $jndiName.getJndiName() -dataStoreHelperClassName com.ibm.websphere.rsadapter.DB2UniversalDataStoreHelper -componentManagedAuthenticationAlias ' + uname + ' -xaRecoveryAuthAlias ' + uname + ' -configureResourceProperties [[databaseName java.lang.String CJSE] [driverType java.lang.Integer 4] [serverName java.lang.String ' + serverName + '] [portNumber java.lang.Integer ' + portNumber + ']]]')
#end

Any help, much appreciated!

Thanks,

Matt
+Pie Number of slices to send: Send
Please Use Code Tags.

print.write(print.toString());


PrintWriter inherits toString() directly from Object, and that's simply what Object's toString() returns - the fully qualified class name (java.io.PrintStream) followed by a @ and the hash code in HEX. As far as I know there is only one Writer that returns its contents with toString(), and that's StringWriter.
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1051 times.
Similar Threads
Is Velocity thread safe?
Velocity Templates with Servlets
Configuring Velocity - ResourceNotFoundException
Velocity Templates with Servlets
Velocity Template is not encoding charecter,instead throwing an error message.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:53:13.