| java.lang.Object HTTPClient.Util
Util | public class Util (Code) | | This class holds various utility methods.
version: 0.3-2 18/06/1999 author: Ronald Tschalär |
Field Summary | |
final static char[] | hex_map |
Method Summary | |
final public static String | assembleHeader(Vector pheader) Assembles a Vector of HttpHeaderElements into a full header string. | final static int[] | compile_search(byte[] search) Creates an array of distances to speed up the search in findStr().
The returned array should be passed as the second argument to
findStr().
Parameters: search - the search string (same as the first argument tofindStr()). | final public static int | defaultPort(String protocol) Return the default port used by a given protocol. | final public static String | dequoteString(String str) Replace quoted characters by their unquoted version. | final static String | escapeUnsafeChars(String path) Escape unsafe characters in a path. | final static int | findSpace(char[] str, int pos) returns the position of the first space character in a char array
starting a position pos. | final static int | findStr(byte[] search, int[] cmp, byte[] str, int beg, int end) Search for a string. | final public static HttpHeaderElement | getElement(Vector header, String name) Get the HttpHeaderElement with the name name. | final public static String | getFragment(String resource) Extract the fragment part from an http resource. | final static Hashtable | getList(Hashtable cntxt_list, Object cntxt) Helper method for context lists used by modules. | final public static String | getParameter(String param, String hdr) retrieves the value associated with the parameter param in
a given header string. | final public static String | getParams(String resource) Extract the params part from an http resource. | final public static String | getPath(String resource) Extract the path from an http resource.
The "resource" part of an HTTP URI can contain a number of parts,
some of which are not always of interest. | final public static String | getQuery(String resource) Extract the query string from an http resource. | final public static boolean | hasToken(String header, String token) Determines if the given header contains a certain token. | final public static String | httpDate(Date date) This returns a string containing the date and time in date
formatted according to a subset of RFC-1123. | final static boolean | needsQuoting(String str) Does the string need to be quoted when sent in a header? I.e. | final public static Vector | parseHeader(String header) This parses the value part of a header. | final public static Vector | parseHeader(String header, boolean dequote) This parses the value part of a header. | final public static String | quoteString(String str, String qlist) Replace given characters by their quoted version. | final static Object[] | resizeArray(Object[] src, int new_size) | final static NVPair[] | resizeArray(NVPair[] src, int new_size) | final static AuthorizationInfo[] | resizeArray(AuthorizationInfo[] src, int new_size) | final static Cookie[] | resizeArray(Cookie[] src, int new_size) | final static String[] | resizeArray(String[] src, int new_size) | final static boolean[] | resizeArray(boolean[] src, int new_size) | final static byte[] | resizeArray(byte[] src, int new_size) | final static char[] | resizeArray(char[] src, int new_size) | final static int[] | resizeArray(int[] src, int new_size) | final public static boolean | sameHttpURL(URL url1, URL url2) Compares two http urls for equality. | final static int | skipSpace(char[] str, int pos) returns the position of the first non-space character in a char array
starting a position pos. | final static int | skipToken(char[] str, int pos) returns the position of the first non-token character in a char array
starting a position pos. | static String[] | splitProperty(String prop) Split a property into an array of Strings, using "|" as the
separator. |
hex_map | final static char[] hex_map(Code) | | |
assembleHeader | final public static String assembleHeader(Vector pheader)(Code) | | Assembles a Vector of HttpHeaderElements into a full header string.
The individual header elements are seperated by a ", ".
Parameters: the - parsed header a string containing the assembled header |
compile_search | final static int[] compile_search(byte[] search)(Code) | | Creates an array of distances to speed up the search in findStr().
The returned array should be passed as the second argument to
findStr().
Parameters: search - the search string (same as the first argument tofindStr()). an array of distances (to be passed as the second argument tofindStr()). |
dequoteString | final public static String dequoteString(String str)(Code) | | Replace quoted characters by their unquoted version. Quoted characters
are characters preceded by a slash. E.g. "\c" would be replaced by "c".
This is used in parsing http headers where quoted-characters are
allowed in quoted-strings and often used to quote the quote character
<">.
Parameters: str - the string do dequote the string do with all quoted characters replaced by theirtrue value. |
escapeUnsafeChars | final static String escapeUnsafeChars(String path)(Code) | | Escape unsafe characters in a path.
Parameters: path - the original path the path with all unsafe characters escaped |
findSpace | final static int findSpace(char[] str, int pos)(Code) | | returns the position of the first space character in a char array
starting a position pos.
Parameters: str - the char array Parameters: pos - the position to start looking the position of the first space character, or the length ofthe string if not found |
findStr | final static int findStr(byte[] search, int[] cmp, byte[] str, int beg, int end)(Code) | | Search for a string. Use compile_search() to first generate the second
argument. This uses a Knuth-Morris-Pratt like algorithm.
Parameters: search - the string to search for. Parameters: cmp - the the array returned by compile_search. Parameters: str - the string in which to look for search. Parameters: beg - the position at which to start the search instr. Parameters: end - the position at which to end the search in str,noninclusive. the position in str where search wasfound, or -1 if not found. |
getElement | final public static HttpHeaderElement getElement(Vector header, String name)(Code) | | Get the HttpHeaderElement with the name name.
Parameters: header - a vector of HttpHeaderElement's, such as is returnedfrom parseHeader() Parameters: name - the name of element to retrieve; matching iscase-insensitive the request element, or null if none found. See Also: Util.parseHeader(java.lang.String) |
getFragment | final public static String getFragment(String resource)(Code) | | Extract the fragment part from an http resource.
Parameters: the - resource to split the fragment, or null if there was none See Also: Util.getPath |
getList | final static Hashtable getList(Hashtable cntxt_list, Object cntxt)(Code) | | Helper method for context lists used by modules. Returns the
list associated with the context if it exists; otherwise it creates
a new list and adds it to the context list.
Parameters: cntxt_list - the list of lists indexed by context Parameters: cntxt - the context |
getParameter | final public static String getParameter(String param, String hdr) throws ParseException(Code) | | retrieves the value associated with the parameter param in
a given header string. It parses the header using
parseHeader() and then searches the first element for the
given parameter. This is used especially in headers like
'Content-type' and 'Content-Disposition'.
quoted characters ("\x") in a quoted string are dequoted.
See Also: Util.parseHeader(java.lang.String) Parameters: param - the parameter name Parameters: hdr - the header value the value for this parameter, or null if not found. exception: ParseException - if the above syntax rules are violated. |
getParams | final public static String getParams(String resource)(Code) | | Extract the params part from an http resource.
Parameters: the - resource to split the params, or null if there are none See Also: Util.getPath |
getPath | final public static String getPath(String resource)(Code) | | Extract the path from an http resource.
The "resource" part of an HTTP URI can contain a number of parts,
some of which are not always of interest. These methods here will
extract the various parts, assuming the following syntanx (taken from
RFC-2068):
resource = [ "/" ] [ path ] [ ";" params ] [ "?" query ] [ "#" fragment ]
Parameters: the - resource to split the path, including any leading "/" See Also: Util.getParams See Also: Util.getQuery See Also: Util.getFragment |
getQuery | final public static String getQuery(String resource)(Code) | | Extract the query string from an http resource.
Parameters: the - resource to split the query, or null if there was none See Also: Util.getPath |
hasToken | final public static boolean hasToken(String header, String token) throws ParseException(Code) | | Determines if the given header contains a certain token. The header
must conform to the rules outlined in parseHeader().
See Also: Util.parseHeader(java.lang.String) Parameters: header - the header value. Parameters: token - the token to find; the match is case-insensitive. true if the token is present, false otherwise. exception: ParseException - if this is thrown parseHeader(). |
httpDate | final public static String httpDate(Date date)(Code) | | This returns a string containing the date and time in date
formatted according to a subset of RFC-1123. The format is defined in
the HTTP/1.0 spec (RFC-1945), section 3.3, and the HTTP/1.1 spec
(RFC-2068), section 3.3.1. Note that Date.toGMTString() is close, but
is missing the weekday and supresses the leading zero if the day is
less than the 10th. Instead we use the SimpleDateFormat class.
Some versions of JDK 1.1.x are bugged in that their GMT uses
daylight savings time... Therefore we use our own timezone
definitions.
Parameters: date - the date and time to be converted a string containg the date and time as used in http |
needsQuoting | final static boolean needsQuoting(String str)(Code) | | Does the string need to be quoted when sent in a header? I.e. does
it contain non-token characters?
Parameters: str - the string true if it needs quoting (i.e. it contains non-token chars) |
parseHeader | final public static Vector parseHeader(String header, boolean dequote) throws ParseException(Code) | | This parses the value part of a header. The result is a Vector of
HttpHeaderElement's. The syntax the header must conform to is:
header = [ element ] *( "," [ element ] )
element = name [ "=" [ value ] ] *( ";" [ param ] )
param = name [ "=" [ value ] ]
name = token
value = ( token | quoted-string )
token = 1*<any char except "=", ",", ";", <"> and
white space>
quoted-string = <"> *( text | quoted-char ) <">
text = any char except <">
quoted-char = "\" char
Any amount of white space is allowed between any part of the header,
element or param and is ignored. A missing value in any element or
param will be stored as the empty string; if the "=" is also missing
null will be stored instead.
Parameters: header - the value part of the header. Parameters: dequote - if true all quoted strings are dequoted. a Vector containing all the elements; each entry is aninstance of HttpHeaderElement. exception: ParseException - if the above syntax rules are violated. See Also: HTTPClient.HttpHeaderElement |
quoteString | final public static String quoteString(String str, String qlist)(Code) | | Replace given characters by their quoted version. Quoted characters
are characters preceded by a slash. E.g. "c" would be replaced by "\c".
This is used in generating http headers where certain characters need
to be quoted, such as the quote character <">.
Parameters: str - the string do quote Parameters: qlist - the list of characters to quote the string do with all characters replaced by theirquoted version. |
resizeArray | final static boolean[] resizeArray(boolean[] src, int new_size)(Code) | | |
resizeArray | final static byte[] resizeArray(byte[] src, int new_size)(Code) | | |
resizeArray | final static char[] resizeArray(char[] src, int new_size)(Code) | | |
resizeArray | final static int[] resizeArray(int[] src, int new_size)(Code) | | |
sameHttpURL | final public static boolean sameHttpURL(URL url1, URL url2)(Code) | | Compares two http urls for equality. This exists because the method
java.net.URL.sameFile() is broken (an explicit port 80
doesn't compare equal to an implicit port, and it doesn't take
escapes into account).
Two http urls are considered equal if they have the same protocol
(case-insensitive match), the same host (case-insensitive), the
same port and the same file (after decoding escaped characters).
Parameters: url1 - the first url Parameters: url1 - the second url true if url1 and url2 compare equal |
skipSpace | final static int skipSpace(char[] str, int pos)(Code) | | returns the position of the first non-space character in a char array
starting a position pos.
Parameters: str - the char array Parameters: pos - the position to start looking the position of the first non-space character |
skipToken | final static int skipToken(char[] str, int pos)(Code) | | returns the position of the first non-token character in a char array
starting a position pos.
Parameters: str - the char array Parameters: pos - the position to start looking the position of the first non-token character, or the lengthof the string if not found |
splitProperty | static String[] splitProperty(String prop)(Code) | | Split a property into an array of Strings, using "|" as the
separator.
|
|
|