Class HTTPClient.Codecs
All Packages  Class Hierarchy  This Package  Previous  Next  Index
  Class HTTPClient.Codecs
java.lang.Object
   |
   +----HTTPClient.Codecs
  -  public class Codecs
  -  extends Object
This class collects various encoders and decoders.
  -  Version:
  
-  0.2 (bug fix 2)  23/03/1997
  
-  Author:
  
-  Ronald Tschalär
   
  -   base64Decode(byte[]) base64Decode(byte[])
-  This method decodes the given byte[] using the base64-encoding
specified in RFC-1521 (Section 5.2).
  
-   base64Decode(String) base64Decode(String)
-  This method decodes the given string using the base64-encoding
specified in RFC-1521 (Section 5.2).
  
-   base64Encode(byte[]) base64Encode(byte[])
-  This method encodes the given byte[] using the base64-encoding
specified in RFC-1521 (Section 5.2).
  
-   base64Encode(String) base64Encode(String)
-  This method encodes the given string using the base64-encoding
specified in RFC-1521 (Section 5.2).
  
-   chunkedDecode(InputStream) chunkedDecode(InputStream)
-  Decodes chunked data.
  
-   chunkedEncode(byte[], NVPair[], boolean) chunkedEncode(byte[], NVPair[], boolean)
-  Encodes data used the chunked encoding.
  
-   getParameter(String, String) getParameter(String, String)
-  retrieves the value associated with the parameter param in
a given header string.
  
-   mpFormDataDecode(byte[], String, String) mpFormDataDecode(byte[], String, String)
-  This method decodes a multipart/form-data encoded string.
  
-   mpFormDataEncode(NVPair[], NVPair[], NVPair[]) mpFormDataEncode(NVPair[], NVPair[], NVPair[])
-  This method encodes name/value pairs and files into a byte array
using the multipart/form-data encoding.
  
-   nv2query(NVPair[]) nv2query(NVPair[])
-  Turns an array of name/value pairs into the string
"name1=value1&name2=value2&name3=value3".
  
-   query2nv(String) query2nv(String)
-  Turns a string of the form "name1=value1&name2=value2&name3=value3"
into an array of name/value pairs.
  
-   quotedPrintableDecode(String) quotedPrintableDecode(String)
-  This method does a quoted-printable decoding of the given string
according to RFC-1521 (Section 5.1).
  
-   quotedPrintableEncode(String) quotedPrintableEncode(String)
-  This method does a quoted-printable encoding of the given string
according to RFC-1521 (Section 5.1).
  
-   URLDecode(String) URLDecode(String)
-  This method decodes the given urlencoded string.
  
-   URLEncode(String) URLEncode(String)
-  This method urlencodes the given string.
   
 base64Encode
base64Encode
  public final static String base64Encode(String str)
  -  This method encodes the given string using the base64-encoding
specified in RFC-1521 (Section 5.2). It's used for example in the
"Basic" authorization scheme.
  
    -  Parameters:
    
-  str - the string
    
-  Returns:
    
-  the base64-encoded str
  
 
 base64Encode
base64Encode
  public final static byte[] base64Encode(byte data[])
  -  This method encodes the given byte[] using the base64-encoding
specified in RFC-1521 (Section 5.2).
  
    -  Parameters:
    
-  data - the data
    
-  Returns:
    
-  the base64-encoded data
  
 
 base64Decode
base64Decode
  public final static String base64Decode(String str)
  -  This method decodes the given string using the base64-encoding
specified in RFC-1521 (Section 5.2).
  
    -  Parameters:
    
-  str - the base64-encoded string.
    
-  Returns:
    
-  the decoded str.
  
 
 base64Decode
base64Decode
  public final static byte[] base64Decode(byte data[])
  -  This method decodes the given byte[] using the base64-encoding
specified in RFC-1521 (Section 5.2).
  
    -  Parameters:
    
-  data - the base64-encoded data.
    
-  Returns:
    
-  the decoded data.
  
 
 quotedPrintableEncode
quotedPrintableEncode
  public final static String quotedPrintableEncode(String str)
  -  This method does a quoted-printable encoding of the given string
according to RFC-1521 (Section 5.1). Note: it assumes 8-bit characters.
  
    -  Parameters:
    
-  str - the string
    
-  Returns:
    
-  the quoted-printable encoded string
  
 
 quotedPrintableDecode
quotedPrintableDecode
  public final static String quotedPrintableDecode(String str) throws ParseException
  -  This method does a quoted-printable decoding of the given string
according to RFC-1521 (Section 5.1).
  
    -  Parameters:
    
-  str - the string
    
-  Returns:
    
-  the decoded string
    
-  Throws: ParseException
    
-  If a '=' is not followed by a valid
                          2-digit hex number or '\r\n'.
  
 
 URLEncode
URLEncode
  public final static String URLEncode(String str)
  -  This method urlencodes the given string. This method is here for
symmetry reasons and just calls URLEncoder.encode().
  
    -  Parameters:
    
-  str - the string
    
-  Returns:
    
-  the url-encoded string
  
 
 URLDecode
URLDecode
  public final static String URLDecode(String str) throws ParseException
  -  This method decodes the given urlencoded string.
  
    -  Parameters:
    
-  str - the url-encoded string
    
-  Returns:
    
-  the decoded string
    
-  Throws: ParseException
    
-  If a '%' is not followed by a valid
                          2-digit hex number.
  
 
 mpFormDataDecode
mpFormDataDecode
  public final static NVPair[] mpFormDataDecode(byte data[],
                                                String cont_type,
                                                String dir) throws IOException, ParseException
  -  This method decodes a multipart/form-data encoded string. The boundary
is parsed from the cont_type parameter, which must be of the
form 'multipart/form-data; boundary=...'.
 Any encoded files are created in the directory specified by
dir using the encoded filename.
 Note: Does not handle nested encodings (yet).
 Example:
    NVPair[] opts = Codecs.mpFormDataDecode(resp.getData(),
                                     resp.getHeader("Content-length"),
                                     ".");
Assuming the data received looked something like:
-----------------------------114975832116442893661388290519
Content-Disposition: form-data; name="option"
                                                         
doit
-----------------------------114975832116442893661388290519
Content-Disposition: form-data; name="comment"; filename="comment.txt"
                                                         
Gnus and Gnats are not Gnomes.
-----------------------------114975832116442893661388290519--
you would get one file called comment.txt in the current
directory, and opts would contain two elements: {"option", "doit"}
and {"comment", "comment.txt"}
    -  Parameters:
    
-  data - the form-data to decode.
    -  cont_type - the content type header (must contain the
			      boundary string).
    -  dir - the directory to create the files in.
    
-  Returns:
    
-  an array of name/value pairs, one for each part;
                       the name is the 'name' attribute given in the
                       Content-Disposition header; the value is either
                       the name of the file if a filename attribute was
                       found, or the contents of the part.
    
-  Throws: IOException
    
-  If any file operation fails.
    
-  Throws: ParseException
    
-  If an error during parsing occurs.
  
 
 getParameter
getParameter
  public final static String getParameter(String param,
                                          String hdr)
  -  retrieves the value associated with the parameter param in
a given header string. This is used especially in headers like
'Content-type' and 'Content-Disposition'. Here is the syntax it
expects:
 ";" param "=" ( token | quoted-string )
    -  Parameters:
    
-  param - the parameter name
    -  hdr - the header value
    
-  Returns:
    
-  the value for this parameter, or null if not found.
  
 
 mpFormDataEncode
mpFormDataEncode
  public final static byte[] mpFormDataEncode(NVPair opts[],
                                              NVPair files[],
                                              NVPair cont_type[]) throws IOException
  -  This method encodes name/value pairs and files into a byte array
using the multipart/form-data encoding. The boundary is returned
as part of cont_type.
 Example:
    NVPair[] opts = { new NVPair("option", "doit") };
    NVPair[] file = { new NVPair("comment", "comment.txt") };
    NVPair[] hdrs = new NVPair[1];
    byte[]   data = Codecs.mpFormDataEncode(opts, file, hdrs);
    con.Post("/cgi-bin/handle-it", data, hdrs);
data will look something like the following:
-----------------------------114975832116442893661388290519
Content-Disposition: form-data; name="option"
                                                         
doit
-----------------------------114975832116442893661388290519
Content-Disposition: form-data; name="comment"; filename="comment.txt"
                                                         
Gnus and Gnats are not Gnomes.
-----------------------------114975832116442893661388290519--
where the "Gnus and Gnats ..." is the contents of the file
comment.txt in the current directory.
    -  Parameters:
    
-  opts - the simple form-data to encode (may be null);
                       for each NVPair the name refers to the 'name'
                       attribute to be used in the header of the part,
                       and the value is contents of the part.
    -  files - the files to encode (may be null); for each
                       NVPair the name refers to the 'name' attribute
                       to be used in the header of the part, and the
                       value is the actual filename (the file will be
                       read and it's contents put in the body of that
                       part).
    -  cont_type - this returns a new NVPair in the 0'th element
                       which contains
			      name = "Content-Type",
			      value = "multipart/form-data; boundary=..."
                       (the reason this parameter is an array is
                       because a) that's the only way to simulate
                       pass-by-reference and b) you need an array for
                       the headers parameter to the Post() or Put()
                       anyway).
    
-  Returns:
    
-  an encoded byte array containing all the opts
			      and files.
    
-  Throws: IOException
    
-  If any file operation fails.
  
 
 nv2query
nv2query
  public final static String nv2query(NVPair pairs[])
  -  Turns an array of name/value pairs into the string
"name1=value1&name2=value2&name3=value3". The names and values are
first urlencoded. This is the form in which form-data is passed to
a cgi script.
  
    -  Parameters:
    
-  pairs - the array of name/value pairs
    
-  Returns:
    
-  a string containg the encoded name/value pairs
  
 
 query2nv
query2nv
  public final static NVPair[] query2nv(String query) throws ParseException
  -  Turns a string of the form "name1=value1&name2=value2&name3=value3"
into an array of name/value pairs. The names and values are
urldecoded. The query string is in the form in which form-data is
received in a cgi script.
  
    -  Parameters:
    
-  query - the query string containing the encoded name/value pairs
    
-  Returns:
    
-  an array of NVPairs
    
-  Throws: ParseException
    
-  If the '=' is missing in any field, or if
				 the urldecoding of the name or value fails
  
 
 chunkedEncode
chunkedEncode
  public final static byte[] chunkedEncode(byte data[],
                                           NVPair ftrs[],
                                           boolean last)
  -  Encodes data used the chunked encoding. last signales if
this is the last chunk, in which case the appropriate footer is
generated.
  
    -  Parameters:
    
-  data - the data to be encoded; may be null.
    -  ftrs - optional headers to include in the footer (ignored if
             not last); may be null.
    -  last - whether this is the last chunk.
    
-  Returns:
    
-  an array of bytes containing the chunk
  
 
 chunkedDecode
chunkedDecode
  public final static Object chunkedDecode(InputStream input) throws ParseException, IOException
  -  Decodes chunked data. The chunks are read from an InputStream, which
is assumed to be correctly positioned. Use 'xxx instanceof byte[]'
and 'xxx instanceof NVPair[]' to determine if this was data or the
last chunk.
  
    -  Parameters:
    
-  input - the stream from which to read the next chunk.
    
-  Returns:
    
-  If this was a data chunk then it returns a byte[]; else
        it's the footer and it returns a NVPair[] containing the
        footers.
    
-  Throws: ParseException
    
-  If any exception during parsing occured.
    
-  Throws: IOException
    
-  If any exception during reading occured.
  
 
All Packages  Class Hierarchy  This Package  Previous  Next  Index