Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

HTTPClient
Class Util  view Util download Util.java

java.lang.Object
  extended byHTTPClient.Util

public class Util
extends java.lang.Object

This class holds various utility methods.

Version:
0.3-2 18/06/1999

Field Summary
(package private) static char[] hex_map
           
private static java.text.SimpleDateFormat http_format
           
private static java.util.BitSet Separators
           
private static java.util.BitSet TokenChar
           
private static java.util.BitSet UnsafeChar
           
 
Constructor Summary
private Util()
          This class isn't meant to be instantiated.
 
Method Summary
static java.lang.String assembleHeader(java.util.Vector pheader)
          Assembles a Vector of HttpHeaderElements into a full header string.
(package private) static int[] compile_search(byte[] search)
          Creates an array of distances to speed up the search in findStr().
static int defaultPort(java.lang.String protocol)
          Deprecated. use URI.defaultPort() instead
static java.lang.String dequoteString(java.lang.String str)
          Replace quoted characters by their unquoted version.
(package private) static java.lang.String escapeUnsafeChars(java.lang.String path)
          Escape unsafe characters in a path.
(package private) static int findSpace(char[] str, int pos)
          returns the position of the first space character in a char array starting a position pos.
(package private) static int findStr(byte[] search, int[] cmp, byte[] str, int beg, int end)
          Search for a string.
static HttpHeaderElement getElement(java.util.Vector header, java.lang.String name)
          Get the HttpHeaderElement with the name name.
static java.lang.String getFragment(java.lang.String resource)
          Extract the fragment part from an http resource.
(package private) static java.util.Hashtable getList(java.util.Hashtable cntxt_list, java.lang.Object cntxt)
          Helper method for context lists used by modules.
static java.lang.String getParameter(java.lang.String param, java.lang.String hdr)
          retrieves the value associated with the parameter param in a given header string.
static java.lang.String getParams(java.lang.String resource)
          Extract the params part from an http resource.
static java.lang.String getPath(java.lang.String resource)
          Extract the path from an http resource.
static java.lang.String getQuery(java.lang.String resource)
          Extract the query string from an http resource.
static boolean hasToken(java.lang.String header, java.lang.String token)
          Determines if the given header contains a certain token.
static java.lang.String httpDate(java.util.Date date)
          This returns a string containing the date and time in date formatted according to a subset of RFC-1123.
(package private) static boolean needsQuoting(java.lang.String str)
          Does the string need to be quoted when sent in a header? I.e.
static java.util.Vector parseHeader(java.lang.String header)
          This parses the value part of a header.
static java.util.Vector parseHeader(java.lang.String header, boolean dequote)
          This parses the value part of a header.
private static java.lang.String parseValue(char[] buf, int[] abeg, java.lang.String header, boolean dequote)
          Parse the value part.
static java.lang.String quoteString(java.lang.String str, java.lang.String qlist)
          Replace given characters by their quoted version.
(package private) static AuthorizationInfo[] resizeArray(AuthorizationInfo[] src, int new_size)
           
(package private) static boolean[] resizeArray(boolean[] src, int new_size)
           
(package private) static byte[] resizeArray(byte[] src, int new_size)
           
(package private) static char[] resizeArray(char[] src, int new_size)
           
(package private) static Cookie[] resizeArray(Cookie[] src, int new_size)
           
(package private) static int[] resizeArray(int[] src, int new_size)
           
(package private) static NVPair[] resizeArray(NVPair[] src, int new_size)
           
(package private) static java.lang.Object[] resizeArray(java.lang.Object[] src, int new_size)
           
(package private) static java.lang.String[] resizeArray(java.lang.String[] src, int new_size)
           
static boolean sameHttpURL(java.net.URL url1, java.net.URL url2)
          Compares two http urls for equality.
(package private) static int skipSpace(char[] str, int pos)
          returns the position of the first non-space character in a char array starting a position pos.
(package private) static int skipToken(char[] str, int pos)
          returns the position of the first non-token character in a char array starting a position pos.
(package private) static java.lang.String[] splitProperty(java.lang.String prop)
          Split a property into an array of Strings, using "|" as the separator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Separators

private static final java.util.BitSet Separators

TokenChar

private static final java.util.BitSet TokenChar

UnsafeChar

private static final java.util.BitSet UnsafeChar

http_format

private static java.text.SimpleDateFormat http_format

hex_map

static final char[] hex_map
Constructor Detail

Util

private Util()
This class isn't meant to be instantiated.

Method Detail

resizeArray

static final java.lang.Object[] resizeArray(java.lang.Object[] src,
                                            int new_size)

resizeArray

static final NVPair[] resizeArray(NVPair[] src,
                                  int new_size)

resizeArray

static final AuthorizationInfo[] resizeArray(AuthorizationInfo[] src,
                                             int new_size)

resizeArray

static final Cookie[] resizeArray(Cookie[] src,
                                  int new_size)

resizeArray

static final java.lang.String[] resizeArray(java.lang.String[] src,
                                            int new_size)

resizeArray

static final boolean[] resizeArray(boolean[] src,
                                   int new_size)

resizeArray

static final byte[] resizeArray(byte[] src,
                                int new_size)

resizeArray

static final char[] resizeArray(char[] src,
                                int new_size)

resizeArray

static final int[] resizeArray(int[] src,
                               int new_size)

splitProperty

static java.lang.String[] splitProperty(java.lang.String prop)
Split a property into an array of Strings, using "|" as the separator.


getList

static final java.util.Hashtable getList(java.util.Hashtable cntxt_list,
                                         java.lang.Object cntxt)
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.


compile_search

static final 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().


findStr

static final int findStr(byte[] search,
                         int[] cmp,
                         byte[] str,
                         int beg,
                         int end)
Search for a string. Use compile_search() to first generate the second argument. This uses a Knuth-Morris-Pratt like algorithm.


dequoteString

public static final java.lang.String dequoteString(java.lang.String str)
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 <">.


quoteString

public static final java.lang.String quoteString(java.lang.String str,
                                                 java.lang.String qlist)
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 <">.


parseHeader

public static final java.util.Vector parseHeader(java.lang.String header)
                                          throws ParseException
This parses the value part of a header. All quoted strings are dequoted.


parseHeader

public static final java.util.Vector parseHeader(java.lang.String header,
                                                 boolean dequote)
                                          throws ParseException
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.


parseValue

private static java.lang.String parseValue(char[] buf,
                                           int[] abeg,
                                           java.lang.String header,
                                           boolean dequote)
                                    throws ParseException
Parse the value part. Accepts either token or quoted string.


hasToken

public static final boolean hasToken(java.lang.String header,
                                     java.lang.String token)
                              throws ParseException
Determines if the given header contains a certain token. The header must conform to the rules outlined in parseHeader().


getElement

public static final HttpHeaderElement getElement(java.util.Vector header,
                                                 java.lang.String name)
Get the HttpHeaderElement with the name name.


getParameter

public static final java.lang.String getParameter(java.lang.String param,
                                                  java.lang.String hdr)
                                           throws ParseException
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.


assembleHeader

public static final java.lang.String assembleHeader(java.util.Vector pheader)
Assembles a Vector of HttpHeaderElements into a full header string. The individual header elements are seperated by a ", ".


skipSpace

static final int skipSpace(char[] str,
                           int pos)
returns the position of the first non-space character in a char array starting a position pos.


findSpace

static final int findSpace(char[] str,
                           int pos)
returns the position of the first space character in a char array starting a position pos.


skipToken

static final int skipToken(char[] str,
                           int pos)
returns the position of the first non-token character in a char array starting a position pos.


needsQuoting

static final boolean needsQuoting(java.lang.String str)
Does the string need to be quoted when sent in a header? I.e. does it contain non-token characters?


sameHttpURL

public static final boolean sameHttpURL(java.net.URL url1,
                                        java.net.URL url2)
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).


defaultPort

public static final int defaultPort(java.lang.String protocol)
Deprecated. use URI.defaultPort() instead

Return the default port used by a given protocol.


httpDate

public static final java.lang.String httpDate(java.util.Date date)
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.


escapeUnsafeChars

static final java.lang.String escapeUnsafeChars(java.lang.String path)
Escape unsafe characters in a path.


getPath

public static final java.lang.String getPath(java.lang.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. These methods here will extract the various parts, assuming the following syntanx (taken from RFC-2068):

 resource = [ "/" ] [ path ] [ ";" params ] [ "?" query ] [ "#" fragment ]
 


getParams

public static final java.lang.String getParams(java.lang.String resource)
Extract the params part from an http resource.


getQuery

public static final java.lang.String getQuery(java.lang.String resource)
Extract the query string from an http resource.


getFragment

public static final java.lang.String getFragment(java.lang.String resource)
Extract the fragment part from an http resource.