public class SegmentConsumer extends ArrayConsumer implements Segment
SegmentConsumer
object provides a consumer that is
used to consume a HTTP header. This will read all headers within a
HTTP header message until the carriage return line feed empty line
is encountered. Once all headers are consumed they are available
using the case insensitive header name. This will remove leading
and trailing whitespace from the names and values parsed.Modifier and Type | Field and Description |
---|---|
protected CookieParser |
cookies
This is used to parse the cookie headers that are consumed.
|
protected ContentDisposition |
disposition
This is used to represent the content disposition header.
|
protected String |
encoding
This represents the transfer encoding value of the body.
|
protected boolean |
expect
This is used to determine if there is a continue expected.
|
protected MessageHeader |
header
This is used to store all consumed headers by the header name.
|
protected LanguageParser |
language
This is used to parse the languages accepted in the request.
|
protected long |
length
Represents the length of the body from the content length.
|
protected long |
limit
This represents the length limit of the HTTP header cosumed.
|
protected String |
name
During parsing this is used to store the parsed header name,
|
protected int |
pos
This is used to track the read offset within the header.
|
protected int |
scan
This is used to track how much of the terminal is read.
|
protected ContentType |
type
This is used to parse the content type header consumed.
|
protected String |
value
During parsing this is used to store the parsed header value.
|
array, chunk, count, done
Constructor and Description |
---|
SegmentConsumer()
Constructor for the
SegmentConsumer object. |
SegmentConsumer(int limit)
Constructor for the
SegmentConsumer object. |
Modifier and Type | Method and Description |
---|---|
protected void |
add(String name,
String value)
This is used to add the name and value specified as a special
header within the segment.
|
protected void |
adjust()
This will update the offset variable so that the next read will
be of a non whitespace character.
|
protected void |
cookie(String value)
This will accept any cookie header and parse it such that all
cookies within it are converted to
Cookie objects
and made available as typed objects. |
protected void |
disposition(String value)
This is used to parse the content disposition header header so
that the MIME type is available to the segment.
|
protected void |
encoding(String value)
This is used to store the transfer encoding header value.
|
protected void |
end()
This will update the offset variable so that the next read will
be a non whitespace character or terminal character.
|
protected boolean |
equal(String name,
String token)
This is used to determine if two header names are equal, this is
done to ensure that the case insensitivity of HTTP header names
is observed.
|
protected void |
expect(String value)
This is used to determine if the expect continue header is
present and thus there is a requirement to send the continue
status before the client sends the request body.
|
long |
getContentLength()
This is a convenience method that can be used to determine
the length of the message body.
|
ContentType |
getContentType()
This is a convenience method that can be used to determine the
content type of the message body.
|
ContentDisposition |
getDisposition()
This is a convenience method that can be used to determine the
content type of the message body.
|
String |
getFileName()
This method is used to acquire the file name of the part.
|
List<Locale> |
getLocales()
This is used to acquire the locales from the request header.
|
String |
getName()
This method is used to acquire the name of the part.
|
String |
getTransferEncoding()
This is a convenience method that can be used to determine the
content type of the message body.
|
String |
getValue(String name)
This can be used to get the value of the first message header
that has the specified name.
|
String |
getValue(String name,
int index)
This can be used to get the value of the first message header
that has the specified name.
|
List<String> |
getValues(String name)
This can be used to get the values of HTTP message headers
that have the specified name.
|
protected void |
headers()
This is used to parse the headers from the consumed HTTP header
and add them to the segment.
|
boolean |
isExpectContinue()
This is used to determine if the header represents one that
requires the HTTP/1.1 continue expectation.
|
boolean |
isFile()
This method is used to determine the type of a part.
|
protected void |
language(String value)
This is used to parse the
Accept-Language header
value. |
protected void |
length(String value)
This is used to parse a provided header value for the content
length.
|
protected void |
process()
This is used to process the headers when the terminal token
has been fully read from the consumed bytes.
|
protected void |
resize(int size)
This method is used to add an additional chunk size to the
internal array.
|
protected int |
scan()
This method is used to scan for the terminal token.
|
protected boolean |
space(byte octet)
This identifies a given ISO-8859-1 byte as a space character.
|
protected boolean |
terminal(byte octet)
This determines if an ISO-8859-1 byte is a terminal character.
|
String |
toString()
This is used to provide a string representation of the header
read.
|
protected void |
type(String value)
This is used to parse the content type header header so that
the MIME type is available to the segment.
|
protected boolean |
white(byte octet)
This is used to determine if a given ISO-8859-1 byte is a white
space character, such as a tab or space or a terminal character,
such as a carriage return or a new line.
|
consume, isFinished
protected ContentDisposition disposition
protected LanguageParser language
protected CookieParser cookies
protected MessageHeader header
protected ContentType type
protected String encoding
protected String name
protected String value
protected boolean expect
protected long length
protected long limit
protected int pos
protected int scan
public SegmentConsumer()
SegmentConsumer
object. This
is used to create a segment consumer used to consume and parse
a HTTP message header. This delegates parsing of headers if
they represent special headers, like content type or cookies.public SegmentConsumer(int limit)
SegmentConsumer
object. This
is used to create a segment consumer used to consume and parse
a HTTP message header. This delegates parsing of headers if
they represent special headers, like content type or cookies.limit
- this is the length limit for a HTTP headerpublic boolean isFile()
public String getName()
public String getFileName()
getFileName
in interface Segment
public ContentType getContentType()
Content-Type
header, if there is then
this will parse that header and represent it as a typed object
which will expose the various parts of the HTTP header.getContentType
in interface Segment
public long getContentLength()
Content-Length
header, if it does then the
length can be determined, if not then this returns -1.getContentLength
in interface Segment
public String getTransferEncoding()
Transfer-Encoding
header, if there is
then this will parse that header and return the first token in
the comma separated list of values, which is the primary value.getTransferEncoding
in interface Segment
public ContentDisposition getDisposition()
Content-Disposition
header, if there is
this will parse that header and represent it as a typed object
which will expose the various parts of the HTTP header.getDisposition
in interface Segment
public List<Locale> getLocales()
Accept-Language
header.
This provides an indication as to the languages that the client
accepts. It provides the locales in preference order.public List<String> getValues(String name)
substring
and trim
calls.
The tokens returned by this method are ordered according to there HTTP quality values, or "q" values, see RFC 2616 section 3.9. This also strips out the quality parameter from tokens returned. So "image/html; q=0.9" results in "image/html". If there are no "q" values present then order is by appearance.
The result from this is either the trimmed header value, that is, the header value with no leading or trailing whitespace or an array of trimmed tokens ordered with the most preferred in the lower indexes, so index 0 is has highest preference.
public String getValue(String name)
public String getValue(String name, int index)
public boolean isExpectContinue()
protected void resize(int size) throws IOException
resize
in class ArrayConsumer
size
- this is the minimum size to expand the array toIOException
protected void process() throws IOException
process
in class ArrayConsumer
IOException
protected void headers()
protected void add(String name, String value)
name
- this is the name of the header to be addedvalue
- this is the value of the header to be addedprotected void expect(String value)
value
- the value in the expect continue headerprotected void cookie(String value)
Cookie
objects
and made available as typed objects. If the value can not be
parsed this will not add the cookie value.value
- this is the value of the cookie to be parsedprotected void language(String value)
Accept-Language
header
value. This allows the locales the client is interested in to
be provided in preference order and allows the client do alter
and response based on the locale the client has provided.value
- this is the value that is to be parsedprotected void type(String value)
ContentType
object to represent
the content type header, which exposes the charset value.value
- this is the content type value to parseprotected void disposition(String value)
Disposition object to represent
the content disposition, this exposes the upload type.
value
- this is the content type value to parseprotected void encoding(String value)
value
- this is the value representing the encodingprotected void length(String value)
value
- this is the header value of the content lengthprotected void adjust()
protected void end()
protected int scan()
scan
in class ArrayConsumer
protected boolean equal(String name, String token)
name
- this is the name to compare the parsed token withtoken
- this is the header name token to examineprotected boolean space(byte octet)
octet
- the byte to determine whether it is a spaceprotected boolean terminal(byte octet)
octet
- the byte to determine whether it is a terminalprotected boolean white(byte octet)
octet
- this is to be checked to see if it is a spacepublic String toString()
Copyright © 2024. All rights reserved.