package class8_1_StreamDecorator_HalfExam2Solution; // 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. Instead, we can call it an adapter. * * 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 * * I needed this to replace System.out with a wrapped version of System.out * (Not sure if there is any reason you would want to do this... * feels rather like a hack!) */ 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); } }