Fields Summary |
---|
public static final String | DEFAULT_ENCODING |
public static final int | DEFAULT_BUFFER_SIZE |
private org.apache.tomcat.util.buf.ByteChunk | bbThe byte buffer. |
private boolean | initialState of the output buffer. |
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 | coyoteResponseAssociated Coyote response. |
private boolean | suspendedSuspended flag. All output bytes will be swallowed if this is true. |
Methods Summary |
---|
public void | checkConverter()
if (!gotEnc)
setConverter();
|
public void | clearEncoders()Clear cached encoders (to save memory for Comet requests).
encoders.clear();
|
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 ((!coyoteResponse.isCommitted())
&& (coyoteResponse.getContentLengthLong() == -1)) {
// If this didn't cause a commit of the response, the final content
// length can be calculated
if (!coyoteResponse.isCommitted()) {
coyoteResponse.setContentLength(bb.getLength());
}
}
doFlush(false);
closed = true;
coyoteResponse.finish();
|
protected void | doFlush(boolean realFlush)Flush bytes or chars contained in the buffer.
if (suspended)
return;
doFlush = true;
if (initial) {
coyoteResponse.sendHeaders();
initial = false;
}
if (bb.getLength() > 0) {
bb.flushBuffer();
}
doFlush = false;
if (realFlush) {
coyoteResponse.action(ActionCode.ACTION_CLIENT_FLUSH,
coyoteResponse);
// If some exception occurred earlier, or if some IOE occurred
// here, notify the servlet with an IOE
if (coyoteResponse.isExceptionPresent()) {
throw new ClientAbortException
(coyoteResponse.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
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.coyoteResponse;
|
public boolean | isClosed()Is the response output closed ?
return this.closed;
|
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 (closed)
return;
if (coyoteResponse == null)
return;
// If we really have something to write
if (cnt > 0) {
// real write to the adapter
outputChunk.setBytes(buf, off, cnt);
try {
coyoteResponse.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.
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 (coyoteResponse != null)
enc = coyoteResponse.getCharacterEncoding();
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 new C2BConverter(bb, enc);
}
}
);
}catch(PrivilegedActionException ex){
Exception e = ex.getException();
if (e instanceof IOException)
throw (IOException)e;
}
} else {
conv = new C2BConverter(bb, enc);
}
encoders.put(enc, conv);
}
|
public void | setEncoding(java.lang.String s)
enc = s;
|
public void | setResponse(org.apache.coyote.Response coyoteResponse)Associated Coyote response.
this.coyoteResponse = coyoteResponse;
|
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;
conv.convert((char) c);
conv.flushBuffer();
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;
conv.convert(c, off, len);
conv.flushBuffer();
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";
conv.convert(s, off, len);
conv.flushBuffer();
|
public void | write(java.lang.String s)
if (suspended)
return;
if (s == null)
s = "null";
conv.convert(s);
conv.flushBuffer();
|
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;
bb.append(b, off, len);
bytesWritten += len;
// if called from within flush(), then immediately flush
// remaining bytes
if (doFlush) {
bb.flushBuffer();
}
|