package example5_3javaiodecorator; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; /** * @author hornick * This output stream decorator adds line numbers to a wrapped output stream */ public class LineNumberDecorator extends FilterOutputStream { private int lineNumber; /** * constructs the output stream decorator * @param wrappedStream */ public LineNumberDecorator(OutputStream wrappedStream) { super(wrappedStream); lineNumber = 0; // initialize line number } /** * accept an array of bytes and forward them to the wrapped output stream * Update Jay Urbain 1/14/2014 */ @Override public void write( byte[] b ) throws IOException { // First, do the line number decorating String ln = "" + lineNumber++ + ":"; for(int j=0; j