Enjoy...

Michael Rutherfurd

package au.com.westpac.itdev.xutil;

import java.io.*;

/**
 * This class combines the functionality of a <code>PrintWriter</code> and a
<code>StringWriter</code>.
 *
 * Extending <code>PrintWriter</code> would be better but unfortunately
won't work due to
 * limitations in the <code>PrintWriter</code> constructors.
 *
 * @author      Michael Rutherfurd
 */
public class PrintStringWriter extends Writer {
        private PrintWriter out;
        private StringWriter buf;
/**
 * Create a new <code>PrintWriter</code>, without automatic line flushing,
from a <code>StringWriter</code>.
 */
public PrintStringWriter() {
        this.buf = new StringWriter();
        this.out = new PrintWriter(buf);
}
/**
 * Returns the encapsulated PrintWriter.
 *
 * @return PrintWriter.
 */
public PrintWriter asPrintWriter() {
        return this.out;
}
/**
 * Flush the stream and check its error state.  Errors are cumulative;
 * once the stream encounters an error, this routine will return true on
 * all successive calls.
 *
 * @return True if the print stream has encountered an error, either on the
 * underlying output stream or during a format conversion.
 */
public boolean checkError() {
        return this.out.checkError();
}
/** Close the stream. */
public void close() {
        this.out.close();
}
/** Flush the stream. */
public void flush() {
        this.out.flush();
}
/**
 * Return the string buffer itself.
 */
public StringBuffer getBuffer() {
        return this.buf.getBuffer();
}
/** Print an array of chracters. */
public void print(char x[]) {
        this.out.print(x);
}
/** Print a character. */
public void print(char x) {
        this.out.print(x);
}
/** Print a double. */
public void print(double x) {
        this.out.print(x);
}
/** Print a float. */
public void print(float x) {
        this.out.print(x);
}
/** Print an integer. */
public void print(int x) {
        this.out.print(x);
}
/** Print a long. */
public void print(long x) {
        this.out.print(x);
}
/** Print an object. */
public void print(Object x) {
        this.out.print(x);
}
/** Print a String. */
public void print(String x) {
        this.out.print(x);
}
/** Print a boolean. */
public void print(boolean x) {
        this.out.print(x);
}
/** Finish the line. */
public void println() {
        this.out.println();
}
/** Print an array of characters, and then finish the line. */
public void println(char x[]) {
        this.out.println(x);
}
/** Print a character, and then finish the line. */
public void println(char x) {
        this.out.println(x);
}
/** Print a double, and then finish the line. */
public void println(double x) {
        this.out.println(x);
}
/** Print a float, and then finish the line. */
public void println(float x) {
        this.out.println(x);
}
/** Print an integer, and then finish the line. */
public void println(int x) {
        this.out.println(x);
}
/** Print a long, and then finish the line. */
public void println(long x) {
        this.out.println(x);
}
/** Print an Object, and then finish the line. */
public void println(Object x) {
        this.out.println(x);
}
/** Print a String, and then finish the line. */
public void println(String x) {
        this.out.println(x);
}
/** Print a boolean, and then finish the line. */
public void println(boolean x) {
        this.out.println(x);
}
/**
 * Return the current value as a string.
 */
public String toString() {
        return this.buf.toString();
}
/** Write a portion of an array of characters. */
public void write(char buf[], int off, int len) {
        this.out.write(buf, off, len);
}
}

> -----Original Message-----
> From: Rohan Shrinivas Desai [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, 29 January 2002 20:04
> To: [EMAIL PROTECTED]
> Subject: Re: Java Servlet HTML
>
>
> hi micheal,
>
>         can u share that class with us if u dont mind ?
>
> Rohan
>
> -----Original Message-----
> From: RUTHERFURD, Michael [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, January 29, 2002 2:23 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Java Servlet HTML
>
>
> I got sick of appending \n to everything so I wrote a Writer
> class that
> combines StringWriter and PrintWriter. You can use
> print/println as normal
> and then use toString to return the buffer.
>
> Michael Rutherfurd
>
> ______________________________________________________________
> _____________
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
> http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
> DISCLAIMER: Information contained and transmitted by this E-MAIL is
> proprietary to MASCOT SYSTEMS LIMITED and is intended for use
> only by the
> individual or entity to which it is addressed, and may
> contain information
> that is privileged, confidential or exempt from disclosure
> under applicable
> law. If this is a forwarded message, the content of this
> E-MAIL may not have
> been sent with the authority of the Company. If you are not
> the intended
> recipient, an agent of the intended recipient or a person
> responsible for
> delivering the information to the named recipient, you are
> notified that any
> use, distribution, transmission, printing, copying or
> dissemination of this
> information in any way or in any manner is strictly
> prohibited. If you have
> received this communication in error, please delete this mail
> & notify us
> immediately at [EMAIL PROTECTED] Before opening attachments,
> please scan for viruses
>
> ______________________________________________________________
> _____________
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
> http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to