FileDocCategorySizeDatePackage
LogOutputStream.javaAPI DocGlassfish v2 API4386Fri May 04 22:35:08 BST 2007com.sun.enterprise.naming

LogOutputStream

public class LogOutputStream extends OutputStream
Capture output lines and send them to the system error log.

Fields Summary
protected Logger
logger
protected Level
level
private int
lastb
private byte[]
buf
private int
pos
Constructors Summary
public LogOutputStream(String facility)
Log to the specified facility at the default FINE level.


                   
       
	this(facility, Level.FINE);
    
public LogOutputStream(String facility, Level level)
Log to the specified facility at the specified level.

	logger = Logger.getLogger(facility);
	this.level = level;
    
Methods Summary
private voidexpandCapacity(int len)
Ensure that the buffer can hold at least len bytes beyond the current position.

	while (pos + len > buf.length) {
	    byte[] nb = new byte[buf.length * 2];
	    System.arraycopy(buf, 0, nb, 0, pos);
	    buf = nb;
	}
    
protected voidlog(java.lang.String msg)
Log the specified message. Can be overridden by subclass to do different logging.

	logger.log(level, msg);
    
private voidlogBuf()
Convert the buffer to a string and log it.

	String msg = new String(buf, 0, pos);
	pos = 0;
	log(msg);
    
public voidwrite(int b)

	if (!logger.isLoggable(level))
	    return;

	if (b == '\r") {
	    logBuf();
	} else if (b == '\n") {
	    if (lastb != '\r")
		logBuf();
	} else {
	    expandCapacity(1);
	    buf[pos++] = (byte)b;
	}
	lastb = b;
    
public voidwrite(byte[] b)

	write(b, 0, b.length);
    
public voidwrite(byte[] b, int off, int len)

	int start = off;
	
	if (!logger.isLoggable(level))
	    return;
	len += off;
	for (int i = start; i < len ; i++) {
	    if (b[i] == '\r") {
		expandCapacity(i - start);
		System.arraycopy(b, start, buf, pos, i - start);
		pos += i - start;
		logBuf();
		start = i + 1;
	    } else if (b[i] == '\n") {
		if (lastb != '\r") {
		    expandCapacity(i - start);
		    System.arraycopy(b, start, buf, pos, i - start);
		    pos += i - start;
		    logBuf();
		}
		start = i + 1;
	    }
	    lastb = b[i];
	}
	if ((len - start) > 0) {
	    expandCapacity(len - start);
	    System.arraycopy(b, start, buf, pos, len - start);
	    pos += len - start;
	}