1 jls.loader.provide('jls.io.PrintStream'); 2 3 jls.loader.require('jls.io.File'); 4 jls.loader.require('jls.io.OutputStreamWriter'); 5 jls.loader.require('jls.io.FileChannel'); 6 jls.loader.require('jls.io.FileOutputStream'); 7 8 jls.io.PrintStream = jls.lang.Class.create(jls.io.OutputStreamWriter, /** @lends jls.io.PrintStream.prototype */ 9 { 10 /** 11 * Creates a print stream. 12 * 13 * @param {jls.io.OutputStream} out The underlying byte output stream or a file, a filename. 14 * @param {String} csn The name of the character set to use. 15 * @constructs 16 * @augments jls.io.OutputStreamWriter 17 * @class A print stream. 18 */ 19 initialize : function($super, out, csn) { 20 // if out is jls.io.FileChannel then jls.io.FileChannel is provided 21 if ((out instanceof jls.io.FileChannel) || (out instanceof jls.io.FileOutputStream)) { 22 // nothing to do 23 } else if ((out instanceof jls.io.File) || (typeof out == 'string')) { 24 out = new jls.io.FileOutputStream(out); 25 } else if ((out instanceof _native.io.FileDesc) || (out instanceof _native.io.StaticFileDesc)) { 26 out = new jls.io.FileChannel(out); 27 } else { 28 throw new jls.lang.Exception('Invalid outputstream'); 29 } 30 $super(out, csn); 31 }, 32 /** 33 * Prints a string. 34 * 35 * @param {String} s The string to write. 36 * @returns {Number} the write byte count. 37 */ 38 print : function(s) { 39 return this.write(s); 40 }, 41 /** 42 * Prints a string. 43 * 44 * @param {String} s The string to write. 45 * @returns {Number} the write byte count. 46 */ 47 println : function(s) { 48 return this.writeLine(s); 49 } 50 }); 51