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

TraceInputStream

public class TraceInputStream extends FilterInputStream
This class is a FilterInputStream that writes the bytes being read from the given input stream into the given output stream. This class is typically used to provide a trace of the data that is being retrieved from an input stream.
author
John Mani

Fields Summary
private boolean
trace
private boolean
quote
private OutputStream
traceOut
Constructors Summary
public TraceInputStream(InputStream in, OutputStream traceOut)
Creates an input stream filter built on top of the specified input stream.

param
in the underlying input stream.
param
out the trace stream


                                           
         
	super(in);
	this.traceOut = traceOut;
    
Methods Summary
public intread()
Reads the next byte of data from this input stream. Returns -1 if no data is available. Writes out the read byte into the trace stream, if trace mode is true

	int b = in.read();
	if (trace && b != -1) {
	    if (quote)
		writeByte(b);
	    else
		traceOut.write(b);
	}
	return b;
    
public intread(byte[] b, int off, int len)
Reads up to len bytes of data from this input stream into an array of bytes. Returns -1 if no more data is available. Writes out the read bytes into the trace stream, if trace mode is true

	int count = in.read(b, off, len);
	if (trace && count != -1) {
	    if (quote) {
		for (int i = 0; i < count; i++)
		    writeByte(b[off + i]);
	    } else
		traceOut.write(b, off, count);
	}
	return count;
    
public voidsetQuote(boolean quote)
Set quote mode.

param
quote the quote mode

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

param
trace the trace mode

	this.trace = trace;
    
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);
	}