FileDocCategorySizeDatePackage
TraceOutputStream.javaAPI DocGlassfish v2 API4469Mon May 14 15:28:46 BST 2007com.sun.mail.util

TraceOutputStream

public class TraceOutputStream extends FilterOutputStream
This class is a subclass of DataOutputStream that copies the data being written into the DataOutputStream into another output stream. This class is used here to provide a debug trace of the stuff thats being written out into the DataOutputStream.
author
John Mani

Fields Summary
private boolean
trace
private boolean
quote
private OutputStream
traceOut
Constructors Summary
public TraceOutputStream(OutputStream out, OutputStream traceOut)
Creates an output stream filter built on top of the specified underlying output stream.

param
out the underlying output stream.
param
traceOut the trace stream.


                             		       
         
	super(out);
	this.traceOut = traceOut;
    
Methods Summary
public voidsetQuote(boolean quote)
Set quote mode.

param
quote the quote mode

	this.quote = quote;
    
public voidsetTrace(boolean trace)
Set the trace mode.

	this.trace = trace;
    
public voidwrite(int b)
Writes the specified byte to this output stream. Writes out the byte into the trace stream if the trace mode is true

	if (trace) {
	    if (quote)
		writeByte(b);
	    else
		traceOut.write(b);
	}
	out.write(b);
    
public voidwrite(byte[] b, int off, int len)
Writes b.length bytes to this output stream. Writes out the bytes into the trace stream if the trace mode is true

	if (trace) {
	    if (quote) {
		for (int i = 0; i < len; i++)
		    writeByte(b[off + i]);
	    } else
		traceOut.write(b, off, len);
	}
	out.write(b, off, len);
    
private final voidwriteByte(int b)
Write a byte in a way that every byte value is printable ASCII.

	b &= 0xff;
	if (b > 0x7f) {
	    traceOut.write('M");
	    traceOut.write('-");
	    b &= 0x7f;
	}
	if (b == '\r") {
	    traceOut.write('\\");
	    traceOut.write('r");
	} else if (b == '\n") {
	    traceOut.write('\\");
	    traceOut.write('n");
	    traceOut.write('\n");
	} else if (b == '\t") {
	    traceOut.write('\\");
	    traceOut.write('t");
	} else if (b < ' ") {
	    traceOut.write('^");
	    traceOut.write('@" + b);
	} else {
	    traceOut.write(b);
	}