Author: costin Date: Sat Nov 19 09:52:07 2005 New Revision: 345662 URL: http://svn.apache.org/viewcvs?rev=345662&view=rev Log: Remove duplicated methods.
Modified: tomcat/sandbox/java/org/apache/coyote/http11/InternalAprInputBuffer.java Modified: tomcat/sandbox/java/org/apache/coyote/http11/InternalAprInputBuffer.java URL: http://svn.apache.org/viewcvs/tomcat/sandbox/java/org/apache/coyote/http11/InternalAprInputBuffer.java?rev=345662&r1=345661&r2=345662&view=diff ============================================================================== --- tomcat/sandbox/java/org/apache/coyote/http11/InternalAprInputBuffer.java (original) +++ tomcat/sandbox/java/org/apache/coyote/http11/InternalAprInputBuffer.java Sat Nov 19 09:52:07 2005 @@ -37,7 +37,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Remy Maucherat</a> */ -public class InternalAprInputBuffer implements InputBuffer { +public class InternalAprInputBuffer extends InternalInputBuffer { // -------------------------------------------------------------- Constants @@ -51,28 +51,12 @@ */ public InternalAprInputBuffer(Request request, int headerBufferSize, long readTimeout) { + super(request, headerBufferSize); - this.request = request; - headers = request.getMimeHeaders(); - - headerBuffer1 = new byte[headerBufferSize]; - headerBuffer2 = new byte[headerBufferSize]; - bodyBuffer = new byte[headerBufferSize]; - buf = headerBuffer1; bbuf = ByteBuffer.allocateDirect(headerBufferSize); - headerBuffer = new char[headerBufferSize]; - ascbuf = headerBuffer; - inputStreamInputBuffer = new SocketInputBuffer(); - filterLibrary = new InputFilter[0]; - activeFilters = new InputFilter[0]; - lastActiveFilter = -1; - - parsingHeader = true; - swallowInput = true; - this.readTimeout = readTimeout * 1000; } @@ -80,91 +64,9 @@ // -------------------------------------------------------------- Variables - - /** - * The string manager for this package. - */ - protected static StringManager sm = - StringManager.getManager(Constants.Package); - - - // ----------------------------------------------------- Instance Variables - - - /** - * Associated Coyote request. - */ - protected Request request; - - - /** - * Headers of the associated request. - */ - protected MimeHeaders headers; - - - /** - * State. - */ - protected boolean parsingHeader; - - - /** - * Swallow input ? (in the case of an expectation) - */ - protected boolean swallowInput; - - - /** - * Pointer to the current read buffer. - */ - protected byte[] buf; - - - /** - * Pointer to the US-ASCII header buffer. - */ - protected char[] ascbuf; - - - /** - * Last valid byte. - */ - protected int lastValid; - - - /** - * Position in the buffer. - */ - protected int pos; - - - /** - * HTTP header buffer no 1. - */ - protected byte[] headerBuffer1; - - - /** - * HTTP header buffer no 2. - */ - protected byte[] headerBuffer2; - - - /** - * HTTP body buffer. - */ - protected byte[] bodyBuffer; - - - /** - * US-ASCII header buffer. - */ - protected char[] headerBuffer; - - /** * Direct byte buffer used to perform actual reading. + * Used instead of super.inputStream */ protected ByteBuffer bbuf; @@ -176,31 +78,6 @@ /** - * Underlying input buffer. - */ - protected InputBuffer inputStreamInputBuffer; - - - /** - * Filter library. - * Note: Filter[0] is always the "chunked" filter. - */ - protected InputFilter[] filterLibrary; - - - /** - * Active filters (in order). - */ - protected InputFilter[] activeFilters; - - - /** - * Index of the last active filter. - */ - protected int lastActiveFilter; - - - /** * The socket timeout used when reading the first block of the request * header. */ @@ -227,75 +104,6 @@ } - /** - * Add an input filter to the filter library. - */ - public void addFilter(InputFilter filter) { - - InputFilter[] newFilterLibrary = - new InputFilter[filterLibrary.length + 1]; - for (int i = 0; i < filterLibrary.length; i++) { - newFilterLibrary[i] = filterLibrary[i]; - } - newFilterLibrary[filterLibrary.length] = filter; - filterLibrary = newFilterLibrary; - - activeFilters = new InputFilter[filterLibrary.length]; - - } - - - /** - * Get filters. - */ - public InputFilter[] getFilters() { - - return filterLibrary; - - } - - - /** - * Clear filters. - */ - public void clearFilters() { - - filterLibrary = new InputFilter[0]; - lastActiveFilter = -1; - - } - - - /** - * Add an input filter to the filter library. - */ - public void addActiveFilter(InputFilter filter) { - - if (lastActiveFilter == -1) { - filter.setBuffer(inputStreamInputBuffer); - } else { - for (int i = 0; i <= lastActiveFilter; i++) { - if (activeFilters[i] == filter) - return; - } - filter.setBuffer(activeFilters[lastActiveFilter]); - } - - activeFilters[++lastActiveFilter] = filter; - - filter.setRequest(request); - - } - - - /** - * Set the swallow input flag. - */ - public void setSwallowInput(boolean swallowInput) { - this.swallowInput = swallowInput; - } - - // --------------------------------------------------------- Public Methods @@ -304,75 +112,12 @@ * connection. */ public void recycle() { + super.recycle(); // Recycle Request object request.recycle(); socket = 0; - buf = headerBuffer1; - lastValid = 0; - pos = 0; - lastActiveFilter = -1; - parsingHeader = true; - swallowInput = true; - - } - - - /** - * 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 nextRequest() - throws IOException { - - // Recycle Request object - request.recycle(); - - // Determine the header buffer used for next request - byte[] newHeaderBuf = null; - if (buf == headerBuffer1) { - newHeaderBuf = headerBuffer2; - } else { - newHeaderBuf = headerBuffer1; - } - - // Copy leftover bytes from buf to newHeaderBuf - System.arraycopy(buf, pos, newHeaderBuf, 0, lastValid - pos); - - // Swap buffers - buf = newHeaderBuf; - - // Recycle filters - for (int i = 0; i <= lastActiveFilter; i++) { - activeFilters[i].recycle(); - } - - // Reset pointers - lastValid = lastValid - pos; - pos = 0; - lastActiveFilter = -1; - parsingHeader = true; - swallowInput = true; - - } - - - /** - * End request (consumes leftover bytes). - * - * @throws IOException an undelying I/O error occured - */ - public void endRequest() - throws IOException { - - if (swallowInput && (lastActiveFilter != -1)) { - int extraBytes = (int) activeFilters[lastActiveFilter].end(); - pos = pos - extraBytes; - } - } @@ -565,198 +310,6 @@ } - - /** - * Parse the HTTP headers. - */ - public void parseHeaders() - throws IOException { - - while (parseHeader()) { - } - - parsingHeader = false; - - } - - - /** - * Parse an HTTP header. - * - * @return false after reading a blank line (which indicates that the - * HTTP header parsing is done - */ - public boolean parseHeader() - throws IOException { - - // - // Check for blank line - // - - byte chr = 0; - while (true) { - - // Read new bytes if needed - if (pos >= lastValid) { - if (!fill()) - throw new EOFException(sm.getString("iib.eof.error")); - } - - chr = buf[pos]; - - if ((chr == Constants.CR) || (chr == Constants.LF)) { - if (chr == Constants.LF) { - pos++; - return false; - } - } else { - break; - } - - pos++; - - } - - // Mark the current buffer position - int start = pos; - - // - // Reading the header name - // Header name is always US-ASCII - // - - boolean colon = false; - MessageBytes headerValue = null; - - while (!colon) { - - // Read new bytes if needed - if (pos >= lastValid) { - if (!fill()) - throw new EOFException(sm.getString("iib.eof.error")); - } - - if (buf[pos] == Constants.COLON) { - colon = true; - headerValue = headers.addValue(ascbuf, start, pos - start); - } - chr = buf[pos]; - if ((chr >= Constants.A) && (chr <= Constants.Z)) { - buf[pos] = (byte) (chr - Constants.LC_OFFSET); - } - - ascbuf[pos] = (char) buf[pos]; - - pos++; - - } - - // Mark the current buffer position - start = pos; - int realPos = pos; - - // - // Reading the header value (which can be spanned over multiple lines) - // - - boolean eol = false; - boolean validLine = true; - - while (validLine) { - - boolean space = true; - - // Skipping spaces - while (space) { - - // Read new bytes if needed - if (pos >= lastValid) { - if (!fill()) - throw new EOFException(sm.getString("iib.eof.error")); - } - - if ((buf[pos] == Constants.SP) || (buf[pos] == Constants.HT)) { - pos++; - } else { - space = false; - } - - } - - int lastSignificantChar = realPos; - - // Reading bytes until the end of the line - while (!eol) { - - // Read new bytes if needed - if (pos >= lastValid) { - if (!fill()) - throw new EOFException(sm.getString("iib.eof.error")); - } - - if (buf[pos] == Constants.CR) { - } else if (buf[pos] == Constants.LF) { - eol = true; - } else if (buf[pos] == Constants.SP) { - buf[realPos] = buf[pos]; - realPos++; - } else { - buf[realPos] = buf[pos]; - realPos++; - lastSignificantChar = realPos; - } - - pos++; - - } - - realPos = lastSignificantChar; - - // Checking the first character of the new line. If the character - // is a LWS, then it's a multiline header - - // Read new bytes if needed - if (pos >= lastValid) { - if (!fill()) - throw new EOFException(sm.getString("iib.eof.error")); - } - - chr = buf[pos]; - if ((chr != Constants.SP) && (chr != Constants.HT)) { - validLine = false; - } else { - eol = false; - // Copying one extra space in the buffer (since there must - // be at least one space inserted between the lines) - buf[realPos] = chr; - realPos++; - } - - } - - // Set the header value - headerValue.setBytes(buf, start, realPos - start); - - return true; - - } - - - // ---------------------------------------------------- InputBuffer Methods - - - /** - * Read some bytes. - */ - public int doRead(ByteChunk chunk, Request req) - throws IOException { - - if (lastActiveFilter == -1) - return inputStreamInputBuffer.doRead(chunk, req); - else - return activeFilters[lastActiveFilter].doRead(chunk,req); - - } // ------------------------------------------------------ Protected Methods --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]