Fields Summary |
---|
private static com.sun.org.apache.commons.logging.Log | log |
public static final String | DEFAULT_ENCODING |
public static final int | DEFAULT_BUFFER_SIZE |
static final int | debug |
private org.apache.tomcat.util.buf.ByteChunk | bbThe byte buffer. |
private int | stateState of the output buffer. |
private boolean | initial |
private int | bytesWrittenNumber of bytes written. |
private int | charsWrittenNumber of chars written. |
private boolean | closedFlag which indicates if the output buffer is closed. |
private boolean | doFlushDo a flush on the next operation. |
private org.apache.tomcat.util.buf.ByteChunk | outputChunkByte chunk used to output bytes. |
private String | encEncoding to use. |
private boolean | gotEncEncoder is set. |
protected HashMap | encodersList of encoders. |
protected org.apache.tomcat.util.buf.C2BConverter | convCurrent char to byte converter. |
private org.apache.coyote.Response | responseAssociated Coyote response. |
private CoyoteResponse | coyoteResponse |
private boolean | suspendedSuspended flag. All output bytes will be swallowed if this is true. |
Methods Summary |
---|
private void | addSessionVersionCookieIfNecessary()Adds a session version cookie to the response if necessary.
CoyoteRequest req = (CoyoteRequest) coyoteResponse.getRequest();
if (req.isRequestedSessionIdFromURL()) {
return;
}
HashMap<String, String> sessionVersions = (HashMap<String, String>)
req.getAttribute(Globals.SESSION_VERSIONS_REQUEST_ATTRIBUTE);
if (sessionVersions != null) {
Cookie cookie = new Cookie(
Globals.SESSION_VERSION_COOKIE_NAME,
RequestUtil.makeSessionVersionString(sessionVersions));
if (sessionVersions.size() > 1
|| coyoteResponse.getContext() == null) {
// Cross-context dispatch
cookie.setPath("/");
} else {
cookie.setPath(coyoteResponse.getContext().getName());
}
response.addHeader("Set-Cookie",
coyoteResponse.getCookieString(cookie));
}
|
public void | checkConverter()
if (!gotEnc)
setConverter();
|
public void | close()Close the output buffer. This tries to calculate the response size if
the response has not been committed yet.
if (closed)
return;
if (suspended)
return;
if ((!response.isCommitted())
&& (response.getContentLength() == -1)) {
// If this didn't cause a commit of the response, the final content
// length can be calculated
if (!response.isCommitted()) {
response.setContentLength(bb.getLength());
}
}
doFlush(false);
closed = true;
response.finish();
|
protected void | doFlush(boolean realFlush)Flush bytes or chars contained in the buffer.
if (suspended)
return;
doFlush = true;
if (initial){
addSessionVersionCookieIfNecessary();
response.sendHeaders();
initial = false;
}
if (bb.getLength() > 0) {
bb.flushBuffer();
}
doFlush = false;
if (realFlush) {
response.action(ActionCode.ACTION_CLIENT_FLUSH, response);
// If some exception occurred earlier, or if some IOE occurred
// here, notify the servlet with an IOE
if (response.isExceptionPresent()) {
throw new ClientAbortException
(response.getErrorException());
}
}
|
public void | flush()Flush bytes or chars contained in the buffer.
doFlush(true);
|
public void | flushBytes()Real write - this buffer will be sent to the client
if (log.isDebugEnabled())
log.debug("flushBytes() " + bb.getLength());
bb.flushBuffer();
|
public int | getBufferSize()
return bb.getLimit();
|
public int | getBytesWritten()
return bytesWritten;
|
public int | getCharsWritten()
return charsWritten;
|
public int | getContentWritten()
return bytesWritten + charsWritten;
|
public org.apache.coyote.Response | getResponse()Get associated Coyote response.
return this.response;
|
public boolean | hasData()Are there any pending writes waiting to be flushed?
if (!suspended && (initial || (bb.getLength() > 0))) {
return true;
}
return false;
|
public boolean | isNew()True if this buffer hasn't been used ( since recycle() ) -
i.e. no chars or bytes have been added to the buffer.
return (bytesWritten == 0) && (charsWritten == 0);
|
public boolean | isSuspended()Is the response output suspended ?
return this.suspended;
|
public void | realWriteBytes(byte[] buf, int off, int cnt)Sends the buffer data to the client output, checking the
state of Response and calling the right interceptors.
if (log.isDebugEnabled())
log.debug("realWrite(b, " + off + ", " + cnt + ") " + response);
if (closed)
return;
if (response == null)
return;
// If we really have something to write
if (cnt > 0) {
addSessionVersionCookieIfNecessary();
// real write to the adapter
outputChunk.setBytes(buf, off, cnt);
try {
response.doWrite(outputChunk);
} catch (IOException e) {
// An IOException on a write is almost always due to
// the remote client aborting the request. Wrap this
// so that it can be handled better by the error dispatcher.
throw new ClientAbortException(e);
}
}
|
public void | recycle()Recycle the output buffer.
if (log.isDebugEnabled())
log.debug("recycle()");
initial = true;
bytesWritten = 0;
charsWritten = 0;
bb.recycle();
closed = false;
suspended = false;
if (conv!= null) {
conv.recycle();
}
gotEnc = false;
enc = null;
|
public void | reset()
bb.recycle();
bytesWritten = 0;
charsWritten = 0;
gotEnc = false;
enc = null;
initial = true;
|
public void | setBufferSize(int size)
if (size > bb.getLimit()) {
bb.setLimit(size);
}
|
protected void | setConverter()
if (response != null)
enc = response.getCharacterEncoding();
if (log.isDebugEnabled())
log.debug("Got encoding: " + enc);
gotEnc = true;
if (enc == null)
enc = DEFAULT_ENCODING;
conv = (C2BConverter) encoders.get(enc);
if (conv == null) {
if (Globals.IS_SECURITY_ENABLED){
try{
conv = (C2BConverter)AccessController.doPrivileged(
new PrivilegedExceptionAction(){
public Object run() throws IOException{
return C2BConverter.getInstance(bb, enc);
}
}
);
}catch(PrivilegedActionException ex){
Exception e = ex.getException();
if (e instanceof IOException)
throw (IOException)e;
if (log.isDebugEnabled())
log.debug("setConverter: " + ex.getMessage());
}
} else {
conv = C2BConverter.getInstance(bb, enc);
}
encoders.put(enc, conv);
}
|
public void | setCoyoteResponse(CoyoteResponse coyoteResponse)
this.coyoteResponse = coyoteResponse;
setResponse((Response) coyoteResponse.getCoyoteResponse());
|
public void | setEncoding(java.lang.String s)
enc = s;
|
public void | setResponse(org.apache.coyote.Response response)Associated Coyote response.
this.response = response;
|
public void | setSuspended(boolean suspended)Set the suspended flag.
this.suspended = suspended;
|
public void | write(byte[] b, int off, int len)
if (suspended)
return;
writeBytes(b, off, len);
|
public void | write(int c)
if (suspended)
return;
checkConverter();
conv.convert((char) c);
charsWritten++;
|
public void | write(char[] c)
if (suspended)
return;
write(c, 0, c.length);
|
public void | write(char[] c, int off, int len)
if (suspended)
return;
checkConverter();
conv.convert(c, off, len);
charsWritten += len;
|
public void | write(java.lang.String s, int off, int len)Append a string to the buffer
if (suspended)
return;
charsWritten += len;
if (s==null)
s="null";
checkConverter();
conv.convert(s, off, len);
|
public void | write(java.lang.String s)
if (suspended)
return;
if (s == null)
s = "null";
checkConverter();
conv.convert(s);
|
public void | writeByte(int b)
if (suspended)
return;
bb.append( (byte)b );
bytesWritten++;
|
private void | writeBytes(byte[] b, int off, int len)
if (closed)
return;
if (log.isDebugEnabled())
log.debug("write(b,off,len)");
bb.append(b, off, len);
bytesWritten += len;
// if called from within flush(), then immediately flush
// remaining bytes
if (doFlush) {
bb.flushBuffer();
}
|