primary
Used to store the characters consumed for the primary type.
ContentType
charset
parameter is one of many parameters that
can be associated with a MIME type. This however this exposes this
parameter with a typed method.
The getCharset
will return the character encoding the
content type is encoded within. This allows the user of the content
to decode it correctly. Other parameters can be acquired from this
by simply providing the name of the parameter.
private ParseBuffer
private ParseBuffer
private ParseBuffer
private ParseBuffer
private ParseBuffer
private ParseBuffer
ContentParser
that contains no charset, primary or secondary.ContentTypeParser(String header)
private void
charset()
charset
param.private void
clear()
private String
encode()
private String
encode(StringBuilder text)
charset
of this MIME
type.getParameter(String name)
getType()
protected void
init()
String
.private void
insert()
private void
insert(ParseBuffer name,
ParseBuffer value)
private void
name()
private void
pack()
String
excluding the whitespace within literals.private void
private void
protected void
parse()
String
object.private void
primary()
private boolean
quote(char ch)
private void
void
setCharset(String enc)
charset
to whatever value the
string contains.void
setParameter(String name,
String value)
void
setPrimary(String value)
void
setSecondary(String value)
toString()
private void
value()
ContentParser
that contains no charset, primary or secondary. This can be used
to extract the primary, secondary and the optional charset
parameter by using the parser's parse(String)
method.String
given to extract the MIME type. This
could be achieved by calling the default no-arg constructor
and then using the instance to invoke the parse
method on that String
.header
- String
containing a MIME type valuegetType
in interface ContentType
setPrimary
in interface ContentType
value
- the type to set for the primary type of thistext/plain; charset=UTF-8
. This will
return the text value. If there is no primary type then this
will return null
otherwise the string value.getPrimary
in interface ContentType
setSecondary
in interface ContentType
value
- the type to set for the primary type of thistext/html; charset=UTF-8
. This
will return the HTML value. If there is no secondary type then
this will return null
otherwise the string value.getSecondary
in interface ContentType
charset
to whatever value the
string contains. If the string is null then this will not set
the parameter to any value and the toString
method
will not contain any details of the parameter.setCharset
in interface ContentType
enc
- parameter value to add to the MIME typecharset
of this MIME
type. This is a special parameter associated with the type, if
the parameter is not contained within the type then this will
return null, which typically means the default of ISO-8859-1.getCharset
in interface ContentType
boundary
or other such parameters are not lost when the header is parsed.
This will return the value, unquoted if required, as a string.getParameter
in interface ContentType
name
- this is the name of the parameter to be retrievedboundary
as well as other
common parameters can be set with this method.setParameter
in interface ContentType
name
- this is the name of the parameter to be addedvalue
- this is the value to associate with the nameString
. This will reset the parser to a
ready state. The init method is invoked by the parser when
the Parser.parse
method is invoked.String
object. This uses the syntax defined by RFC 2616 for the media-type
syntax. This parser is only concerned with one parameter, the
charset
parameter. The syntax for the media type is
media-type = token "/" token *( ";" parameter ) parameter = token | literal
String
excluding the whitespace within literals.
The definition of a literal can be found in RFC 2616.
The definition of a literal for RFC 2616 is anything between 2 quotes but excluding quotes that are prefixed with the backward slash character.
ParseBuffer
. This will read all chars
upto but not including the first instance of a '/'. The type
of a media-type as defined by RFC 2616 is
type/subtype;param=val;param2=val
.ParseBuffer
. This will read all chars
upto but not including the first instance of a ';'. The subtype
of a media-type as defined by RFC 2616 is
type/subtype;param=val;param2=val
.charset
parameter within the set of parameters
which are given to the type. The charset
param is the
only parameter that this parser will tokenize.
This will remove any parameters that preceed the charset parameter.
Once the charset
is retrived the MIME type is considered
to be parsed.
name
- this is the name of the value to be insertedvalue
- this is the value of a that is to be insertedtype/subtype;param=val
etc. The parameter
name and value are not stored. This is used to simply update the read
offset past the parameter. The reason for reading the parameters is to
search for the charset
parameter which will indicate the
encoding.IndexOutOfBoundsException
as each offset
is checked before it is acccessed.char
's upto but excluding the first terminal char
encountered from the off within the buf, or if the value is a literal
it will read a literal from the buffer (literal is any data between
quotes except if the quote is prefixed with a backward slash character).ch
- the character to determine if it is a quotationcharset
param.
This will fill the charset
ParseBuffer
and with
the charset
value. This will read a literal or a token as
the charset
value. If the charset
is a literal
then the quotes will be read as part of the charset.charset
parameter to the type which will
recreate the content type.charset
parameter to the type which will
recreate the content type.text
- this is the buffer to encode the parameters tocharset
parameter to the type which will
recreate the content type.toString
in interface ContentType
toString
in class Object