java.lang.Object
|
+--stec.net.Utils
public class Utils
Includes methods for encoding/decoing URLs, encoding/parsing/extracting
cookies, parsing character set and getting arguments.
Methods
|
Method
|
Description
|
|
concatPaths
|
Concatenates two path strings.
|
|
decodeURL
|
Converts the given x-www-form-urlencoded MIME encoded string into a string.
|
|
encodeCookie
|
Converts the given Cookie into a string.
|
|
encodeURL
|
Converts the given string into a x-www-form-urlencoded MIME encoded string.
|
|
extractCookie
|
Returns the named Cookie from the given array of Cookies.
|
|
getArgs
|
Returns any arguments sent with the request.
|
|
getParameters
|
Returns any parameters sent with the request.
|
|
parseCharacterEncoding
|
Returns the character set using the given content type.
|
|
parseCookieHeader
|
Returns an array of Cookies using the given cookie header.
|
|
readLine
|
Reads a line from the specified input stream to the given byte buffer
starting at the specified offset, upto the given given number of bytes.
|
concatPaths
Concatenates two path strings.
Syntax
public final static String concatPaths(String path1, String path2)
Parameters
|
path1
|
the first path.
|
|
path2
|
the second path.
|
Returns
|
String
|
the resultant path.
|
Throws
Example
String path = Utils.concatPaths(basedir, filepath);
decodeURL
Converts the given x-www-form-urlencoded MIME encoded string into a string.
Syntax
public final static String decodeURL(String url) throws IllegalArgumentException
Parameters
Returns
Throws
|
IllegalArgumentException
|
Thrown when parsing invalid hexadecimal value.
|
Example
String url = Utils.decodeURL(queryString);
encodeCookie
Converts the given Cookie into a string.
Syntax
public final static String encodeCookie(Cookie cookie)
Parameters
|
cookie
|
the Cookie to encode.
|
Returns
|
String
|
the encoded Cookie.
|
Throws
Example
String sCookie = Utils.encodeCookie(cookie);
encodeURL
Converts the given string into a x-www-form-urlencoded MIME encoded string.
Syntax
public final static String encodeURL(String url)
Parameters
Returns
Throws
Example
String eurl = Utils.encodeURL(url);
extractCookie
Returns the named Cookie from the given array of Cookies.
Syntax
public static Cookie extractCookie(Cookie[] cookies, String name)
Parameters
|
cookies
|
the array of cookies to use.
|
|
name
|
the name of the cookie to extract.
|
Returns
|
Cookie
|
the associated Cookie, null if not found.
|
Throws
Example
Cookie cookie = Utils.extractCookie(cookies, key);
getArgs
Returns any arguments sent with request. Arguments are found before any
parameters.
Syntax
public static String getArgs(HttpServletRequest request)
Parameters
|
request
|
the client's request.
|
Returns
|
String
|
any arguments, null if none found.
|
Throws
Example
String args = Utils.getArgs(request);
getParameters
Returns any parameters sent with request. Parameters are found after any
arguments.
Syntax
public static String getParameters(HttpServletRequest request)
Parameters
|
request
|
the client's request.
|
Returns
|
String
|
any parameters, null if none found.
|
Throws
Example
String params = Utils.getParameters(request);
parseCharacterEncoding
Returns the character set using the given content type.
Syntax
public final static String parseCharacterEncoding(String contentType)
Parameters
|
contentType
|
the content type.
|
Returns
|
String
|
the character set, if charset is not found then ISO-8859-1 is
used.
|
Throws
Example
String charset = Utils.parseCharacterEncoding(contentType);
parseCookieHeader
Returns an array of Cookies using the given cookie header.
Syntax
public final static Cookie[] parseCookieHeader(String header)
Parameters
|
header
|
the cookie header.
|
Returns
|
Cookie[]
|
an array of Cookies.
|
Throws
Example
Cookie[] cookies = Utils.parseCookieHeader(header);
readLine
Reads a line from the specified input stream to the given byte buffer
starting at the specified offset, upto the given given number of bytes.
Syntax
public final static int readLine(byte[] buffer,
int offset,
int length)
throws IOException
Parameters
|
buffer
|
the byte array that the line will be read into.
|
|
offset
|
the starting index.
|
|
length
|
the maximum number of bytes to read.
|
Returns
|
int
|
the number of bytes read, -1 if end of stream.
|
Throws
|
java.io.IOException.
|
Thrown if an input exception occured.
|
Example
int bytesRead = Utils.readLine(buffer, 0, buffer.length);
|