• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unexpected characters using PrintWriter

 
matt woodford
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic