• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Unexpected characters using PrintWriter

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22702
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic