package class5_2_StreamDecorator_inClass; // MSOE. Dr. Yoder. 15 January 2016. import java.io.PrintStream; import java.io.Writer; /** * This is an adaptor PrintStream that wraps a Writer. Because Writer and PrintStream have different interfaces, * this is technically NOT a decorator. * * Bytes are converted to chars using the platform default encoding. * If this encoding is not a single-byte encoding, some data may be lost. * * This class relies on WriterOutputStream, which is courtesy of * http://www.coderanch.com/t/278540/java-io/java/create-PrintStream-PrintWriter */ public class WriterPrintStream extends PrintStream { /** * Creates a new PrintStream. This stream will flush automatically. * * @param out The Writer to which values and objects will be * printed. */ public WriterPrintStream(Writer out) { super(new WriterOutputStream(out),true); } }