| Method from org.apache.coyote.http11.InternalOutputBuffer Detail: |
public void addActiveFilter(OutputFilter filter) {
if (lastActiveFilter == -1) {
filter.setBuffer(outputStreamOutputBuffer);
} else {
for (int i = 0; i < = lastActiveFilter; i++) {
if (activeFilters[i] == filter)
return;
}
filter.setBuffer(activeFilters[lastActiveFilter]);
}
activeFilters[++lastActiveFilter] = filter;
filter.setResponse(response);
}
Add an output filter to the filter library. |
public void addFilter(OutputFilter filter) {
OutputFilter[] newFilterLibrary =
new OutputFilter[filterLibrary.length + 1];
for (int i = 0; i < filterLibrary.length; i++) {
newFilterLibrary[i] = filterLibrary[i];
}
newFilterLibrary[filterLibrary.length] = filter;
filterLibrary = newFilterLibrary;
activeFilters = new OutputFilter[filterLibrary.length];
}
Add an output filter to the filter library. |
public void clearFilters() {
filterLibrary = new OutputFilter[0];
lastActiveFilter = -1;
}
|
protected void commit() throws IOException {
// The response is now committed
committed = true;
response.setCommitted(true);
if (pos > 0) {
// Sending the response header buffer
if (useSocketBuffer) {
socketBuffer.append(buf, 0, pos);
} else {
outputStream.write(buf, 0, pos);
}
}
}
|
public int doWrite(ByteChunk chunk,
Response res) throws IOException {
if (!committed) {
// Send the connector a request for commit. The connector should
// then validate the headers, send them (using sendHeaders) and
// set the filters accordingly.
response.action(ActionCode.ACTION_COMMIT, null);
}
if (lastActiveFilter == -1)
return outputStreamOutputBuffer.doWrite(chunk, res);
else
return activeFilters[lastActiveFilter].doWrite(chunk, res);
}
Write the contents of a byte chunk. |
public void endHeaders() {
buf[pos++] = Constants.CR;
buf[pos++] = Constants.LF;
}
|
public void endRequest() throws IOException {
if (!committed) {
// Send the connector a request for commit. The connector should
// then validate the headers, send them (using sendHeader) and
// set the filters accordingly.
response.action(ActionCode.ACTION_COMMIT, null);
}
if (finished)
return;
if (lastActiveFilter != -1)
activeFilters[lastActiveFilter].end();
if (useSocketBuffer) {
socketBuffer.flushBuffer();
}
finished = true;
}
|
public void flush() throws IOException {
if (!committed) {
// Send the connector a request for commit. The connector should
// then validate the headers, send them (using sendHeader) and
// set the filters accordingly.
response.action(ActionCode.ACTION_COMMIT, null);
}
// Flush the current buffer
if (useSocketBuffer) {
socketBuffer.flushBuffer();
}
}
|
public OutputFilter[] getFilters() {
return filterLibrary;
}
|
public OutputStream getOutputStream() {
return outputStream;
}
Get the underlying socket output stream. |
public void nextRequest() {
// Recycle Request object
response.recycle();
socketBuffer.recycle();
// Recycle filters
for (int i = 0; i < = lastActiveFilter; i++) {
activeFilters[i].recycle();
}
// Reset pointers
pos = 0;
lastActiveFilter = -1;
committed = false;
finished = false;
}
End processing of current HTTP request.
Note: All bytes of the current request should have been already
consumed. This method only resets all the pointers so that we are ready
to parse the next HTTP request. |
public void realWriteBytes(byte[] cbuf,
int off,
int len) throws IOException {
if (len > 0) {
outputStream.write(cbuf, off, len);
}
}
Callback to write data from the buffer. |
public void recycle() {
// Recycle Request object
response.recycle();
socketBuffer.recycle();
outputStream = null;
pos = 0;
lastActiveFilter = -1;
committed = false;
finished = false;
}
Recycle the output buffer. This should be called when closing the
connection. |
public void reset() {
if (committed)
throw new IllegalStateException(/*FIXME:Put an error message*/);
// Recycle Request object
response.recycle();
}
|
public void sendAck() throws IOException {
if (!committed)
outputStream.write(Constants.ACK_BYTES);
}
|
public void sendHeader(MessageBytes name,
MessageBytes value) {
write(name);
buf[pos++] = Constants.COLON;
buf[pos++] = Constants.SP;
write(value);
buf[pos++] = Constants.CR;
buf[pos++] = Constants.LF;
}
|
public void sendHeader(ByteChunk name,
ByteChunk value) {
write(name);
buf[pos++] = Constants.COLON;
buf[pos++] = Constants.SP;
write(value);
buf[pos++] = Constants.CR;
buf[pos++] = Constants.LF;
}
|
public void sendHeader(String name,
String value) {
write(name);
buf[pos++] = Constants.COLON;
buf[pos++] = Constants.SP;
write(value);
buf[pos++] = Constants.CR;
buf[pos++] = Constants.LF;
}
|
public void sendStatus() {
// Write protocol name
write(Constants.HTTP_11_BYTES);
buf[pos++] = Constants.SP;
// Write status code
int status = response.getStatus();
switch (status) {
case 200:
write(Constants._200_BYTES);
break;
case 400:
write(Constants._400_BYTES);
break;
case 404:
write(Constants._404_BYTES);
break;
default:
write(status);
}
buf[pos++] = Constants.SP;
// Write message
String message = response.getMessage();
if (message == null) {
write(getMessage(status));
} else {
write(message);
}
// End the response status line
if (org.apache.coyote.Constants.IS_SECURITY_ENABLED){
AccessController.doPrivileged(
new PrivilegedAction(){
public Object run(){
buf[pos++] = Constants.CR;
buf[pos++] = Constants.LF;
return null;
}
}
);
} else {
buf[pos++] = Constants.CR;
buf[pos++] = Constants.LF;
}
}
Send the response status line. |
public void setOutputStream(OutputStream outputStream) {
// ------------------------------------------------------------- Properties
// FIXME: Check for null ?
this.outputStream = outputStream;
}
Set the underlying socket output stream. |
public void setSocketBuffer(int socketBufferSize) {
if (socketBufferSize > 500) {
useSocketBuffer = true;
socketBuffer.allocate(socketBufferSize, socketBufferSize);
} else {
useSocketBuffer = false;
}
}
Set the socket buffer size. |
protected void write(MessageBytes mb) {
if (mb.getType() == MessageBytes.T_BYTES) {
ByteChunk bc = mb.getByteChunk();
write(bc);
} else if (mb.getType() == MessageBytes.T_CHARS) {
CharChunk cc = mb.getCharChunk();
write(cc);
} else {
write(mb.toString());
}
}
This method will write the contents of the specyfied message bytes
buffer to the output stream, without filtering. This method is meant to
be used to write the response header. |
protected void write(ByteChunk bc) {
// Writing the byte chunk to the output buffer
int length = bc.getLength();
System.arraycopy(bc.getBytes(), bc.getStart(), buf, pos, length);
pos = pos + length;
}
This method will write the contents of the specyfied message bytes
buffer to the output stream, without filtering. This method is meant to
be used to write the response header. |
protected void write(CharChunk cc) {
int start = cc.getStart();
int end = cc.getEnd();
char[] cbuf = cc.getBuffer();
for (int i = start; i < end; i++) {
char c = cbuf[i];
// Note: This is clearly incorrect for many strings,
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
if ((c < = 31) && (c != 9)) {
c = ' ";
} else if (c == 127) {
c = ' ";
}
buf[pos++] = (byte) c;
}
}
This method will write the contents of the specyfied char
buffer to the output stream, without filtering. This method is meant to
be used to write the response header. |
public void write(byte[] b) {
// Writing the byte chunk to the output buffer
System.arraycopy(b, 0, buf, pos, b.length);
pos = pos + b.length;
}
This method will write the contents of the specyfied byte
buffer to the output stream, without filtering. This method is meant to
be used to write the response header. |
protected void write(String s) {
if (s == null)
return;
// From the Tomcat 3.3 HTTP/1.0 connector
int len = s.length();
for (int i = 0; i < len; i++) {
char c = s.charAt (i);
// Note: This is clearly incorrect for many strings,
// but is the only consistent approach within the current
// servlet framework. It must suffice until servlet output
// streams properly encode their output.
if ((c < = 31) && (c != 9)) {
c = ' ";
} else if (c == 127) {
c = ' ";
}
buf[pos++] = (byte) c;
}
}
This method will write the contents of the specyfied String to the
output stream, without filtering. This method is meant to be used to
write the response header. |
protected void write(int i) {
write(String.valueOf(i));
}
This method will print the specified integer to the output stream,
without filtering. This method is meant to be used to write the
response header. |