com.sun.grizzly.http.algorithms
Class ContentLengthAlgorithm

java.lang.Object
  extended by com.sun.grizzly.http.algorithms.StreamAlgorithmBase
      extended by com.sun.grizzly.http.algorithms.ContentLengthAlgorithm
All Implemented Interfaces:
StreamAlgorithm
Direct Known Subclasses:
SeekHeaderAlgorithm

public class ContentLengthAlgorithm
extends StreamAlgorithmBase

Predict if the NIO channel has been fully read or not. This lagorithm will first search for the content-length header, and use that value to determine if the bytes has been fully read or not. If the content-length isn't included, it will search for the end of the HTTP stream, which is a '\r\n' Note: the parsing algorithm is an adaptation of: org.apache.coyote.http11.InternalInputBuffer written by Remy Maucherat

Author:
Jean-Francois Arcand

Nested Class Summary
 
Nested classes/interfaces inherited from class com.sun.grizzly.http.algorithms.StreamAlgorithmBase
StreamAlgorithmBase.DummyHandler
 
Field Summary
 byte[] ascbuf
          Pointer to the US-ASCII header buffer.
protected static byte[] CL_HEADER
           
protected  boolean isFound
          Is the content-length fully read.
protected  int lastValid
          Last valid byte.
 int lengthReq
          The request bytes length
protected  int pos
          Position in the buffer.
protected static byte[] POST_METHOD
           
protected static byte[] PUT_METHOD
           
protected  boolean requestLineParsed
          Is the request line parsed?
 int startReq
          The request bytes position.
 
Fields inherited from class com.sun.grizzly.http.algorithms.StreamAlgorithmBase
contentLength, curLimit, curPosition, handler, headerLength, lastStatePosition, primaryByteBuffer, socketChannel, state, useByteBufferView, useDirectByteBuffer
 
Constructor Summary
ContentLengthAlgorithm()
           
 
Method Summary
protected  int findBytes(byte[] buff, int start, int end, byte[] b)
          Compare two bytes array and return > 0 if true.
 Interceptor getHandler()
          Return the Interceptor used by this algorithm.
 boolean parse(ByteBuffer byteBuffer)
          Parse the ByteBuffer and try to determine if the bytes stream has been fully read from the SocketChannel.
protected  boolean parseHeader(ByteBuffer byteBuffer)
          Parse the headers, looking for content-length header and value.
protected  boolean parseRequestLine(ByteBuffer byteBuffer)
          Parse the request line, looking for a POST method.
 void recycle()
          Recylce this object.
 
Methods inherited from class com.sun.grizzly.http.algorithms.StreamAlgorithmBase
allocate, contentLength, dump, getPort, headerLength, postParse, preParse, rollbackParseState, setPort, setSocketChannel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

POST_METHOD

protected static final byte[] POST_METHOD

PUT_METHOD

protected static final byte[] PUT_METHOD

CL_HEADER

protected static final byte[] CL_HEADER

ascbuf

public byte[] ascbuf
Pointer to the US-ASCII header buffer.


lastValid

protected int lastValid
Last valid byte.


pos

protected int pos
Position in the buffer.


isFound

protected boolean isFound
Is the content-length fully read.


requestLineParsed

protected boolean requestLineParsed
Is the request line parsed?


startReq

public int startReq
The request bytes position.


lengthReq

public int lengthReq
The request bytes length

Constructor Detail

ContentLengthAlgorithm

public ContentLengthAlgorithm()
Method Detail

parse

public boolean parse(ByteBuffer byteBuffer)
Parse the ByteBuffer and try to determine if the bytes stream has been fully read from the SocketChannel. Drain the SocketChannel and determine if the request bytes has been fully read. For POST method, parse the bytes and seek for the content-type header to determine the length of the request bytes.

Specified by:
parse in interface StreamAlgorithm
Specified by:
parse in class StreamAlgorithmBase
Parameters:
byteBuffer - the bytes read.
Returns:
true if we need to call back the SelectorThread This occurs when the stream doesn't contains all the request bytes. false if the stream contains all request bytes.

parseRequestLine

protected boolean parseRequestLine(ByteBuffer byteBuffer)
Parse the request line, looking for a POST method.


parseHeader

protected boolean parseHeader(ByteBuffer byteBuffer)
Parse the headers, looking for content-length header and value.


findBytes

protected int findBytes(byte[] buff,
                        int start,
                        int end,
                        byte[] b)
Compare two bytes array and return > 0 if true.


recycle

public void recycle()
Recylce this object.

Specified by:
recycle in interface StreamAlgorithm
Overrides:
recycle in class StreamAlgorithmBase

getHandler

public Interceptor getHandler()
Return the Interceptor used by this algorithm.

Returns:
Interceptor


Copyright © 2011 SUN Microsystems. All Rights Reserved.