Java Doc for Codecs.java in  » Net » SkunkDAV » HTTPClient » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » SkunkDAV » HTTPClient 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   HTTPClient.Codecs

Codecs
public class Codecs (Code)
This class collects various encoders and decoders.
version:
   0.3-2 18/06/1999
author:
   Ronald Tschalär




Method Summary
final public static  StringURLDecode(String str)
     This method decodes the given urlencoded string.
final public static  StringURLEncode(String str)
     This method urlencodes the given string.
final public static  Stringbase64Decode(String str)
     This method decodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8).
Parameters:
  str - the base64-encoded string.
final public static  byte[]base64Decode(byte[] data)
     This method decodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8).
Parameters:
  data - the base64-encoded data.
final public static  Stringbase64Encode(String str)
     This method encodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8).
final public static  byte[]base64Encode(byte[] data)
     This method encodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8).
final public static  ObjectchunkedDecode(InputStream input)
     Decodes chunked data.
final public static  byte[]chunkedEncode(byte[] data, NVPair[] ftrs, boolean last)
     Encodes data used the chunked encoding.
final public static  byte[]chunkedEncode(byte[] data, int off, int len, NVPair[] ftrs, boolean last)
     Encodes data used the chunked encoding.
final static  intgetChunkLength(InputStream input)
     Gets the length of the chunk.
Parameters:
  input - the stream from which to read the next chunk.
final public static  NVPair[]mpFormDataDecode(byte[] data, String cont_type, String dir)
     This method decodes a multipart/form-data encoded string.
Parameters:
  data - the form-data to decode.
Parameters:
  cont_type - the content type header (must contain theboundary string).
Parameters:
  dir - the directory to create the files in.
final public static  NVPair[]mpFormDataDecode(byte[] data, String cont_type, String dir, FilenameMangler mangler)
     This method decodes a multipart/form-data encoded string.
final public static  byte[]mpFormDataEncode(NVPair[] opts, NVPair[] files, NVPair[] cont_type)
     This method encodes name/value pairs and files into a byte array using the multipart/form-data encoding.
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.
Parameters:
  files - the files to encode (may be null); for eachNVPair the name refers to the 'name' attributeto be used in the header of the part, and thevalue is the actual filename (the file will beread and it's contents put in the body of thatpart).
Parameters:
  cont_type - this returns a new NVPair in the 0'th elementwhich containsname = "Content-Type",value = "multipart/form-data; boundary=..."(the reason this parameter is an array isbecause a) that's the only way to simulatepass-by-reference and b) you need an array forthe headers parameter to the Post() or Put()anyway).
final public static  byte[]mpFormDataEncode(NVPair[] opts, NVPair[] files, NVPair[] cont_type, FilenameMangler mangler)
     This method encodes name/value pairs and files into a byte array using the multipart/form-data encoding.
final public static  Stringnv2query(NVPair pairs)
     Turns an array of name/value pairs into the string "name1=value1&name2=value2&name3=value3".
final public static  NVPair[]query2nv(String query)
     Turns a string of the form "name1=value1&name2=value2&name3=value3" into an array of name/value pairs.
final public static  StringquotedPrintableDecode(String str)
     This method does a quoted-printable decoding of the given string according to RFC-2045 (Section 6.7).
final public static  StringquotedPrintableEncode(String str)
     This method does a quoted-printable encoding of the given string according to RFC-2045 (Section 6.7).
final public static  byte[]uudecode(char[] data)
     This method decodes the given uuencoded char[].

Note: just the actual data is decoded; any 'begin' and 'end' lines such as those generated by the unix uuencode utility must not be included.
Parameters:
  data - the uuencode-encoded data.

final public static  char[]uuencode(byte[] data)
     This method encodes the given byte[] using the unix uuencode encding.



Method Detail
URLDecode
final public static String URLDecode(String str) throws ParseException(Code)
This method decodes the given urlencoded string.
Parameters:
  str - the url-encoded string the decoded string
exception:
  ParseException - If a '%' is not followed by a valid2-digit hex number.



URLEncode
final public static String URLEncode(String str)(Code)
This method urlencodes the given string. This method is here for symmetry reasons and just calls java.net.URLEncoder.encode().
Parameters:
  str - the string the url-encoded string



base64Decode
final public static String base64Decode(String str)(Code)
This method decodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8).
Parameters:
  str - the base64-encoded string. the decoded str.



base64Decode
final public static byte[] base64Decode(byte[] data)(Code)
This method decodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8).
Parameters:
  data - the base64-encoded data. the decoded data.



base64Encode
final public static String base64Encode(String str)(Code)
This method encodes the given string using the base64-encoding specified in RFC-2045 (Section 6.8). It's used for example in the "Basic" authorization scheme.
Parameters:
  str - the string the base64-encoded str



base64Encode
final public static byte[] base64Encode(byte[] data)(Code)
This method encodes the given byte[] using the base64-encoding specified in RFC-2045 (Section 6.8).
Parameters:
  data - the data the base64-encoded data



chunkedDecode
final public static Object chunkedDecode(InputStream input) throws ParseException, IOException(Code)
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. If this was a data chunk then it returns a byte[]; elseit's the footer and it returns a NVPair[] containing thefooters.
exception:
  ParseException - If any exception during parsing occured.
exception:
  IOException - If any exception during reading occured.



chunkedEncode
final public static byte[] chunkedEncode(byte[] data, NVPair[] ftrs, boolean last)(Code)
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.
Parameters:
  ftrs - optional headers to include in the footer (ignored ifnot last); may be null.
Parameters:
  last - whether this is the last chunk. an array of bytes containing the chunk



chunkedEncode
final public static byte[] chunkedEncode(byte[] data, int off, int len, NVPair[] ftrs, boolean last)(Code)
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.
Parameters:
  off - an offset into the data
Parameters:
  len - the number of bytes to take from data
Parameters:
  ftrs - optional headers to include in the footer (ignored ifnot last); may be null.
Parameters:
  last - whether this is the last chunk. an array of bytes containing the chunk



getChunkLength
final static int getChunkLength(InputStream input) throws ParseException, IOException(Code)
Gets the length of the chunk.
Parameters:
  input - the stream from which to read the next chunk. the length of chunk to follow (w/o trailing CR LF).
exception:
  ParseException - If any exception during parsing occured.
exception:
  IOException - If any exception during reading occured.



mpFormDataDecode
final public static NVPair[] mpFormDataDecode(byte[] data, String cont_type, String dir) throws IOException, ParseException(Code)
This method decodes a multipart/form-data encoded string.
Parameters:
  data - the form-data to decode.
Parameters:
  cont_type - the content type header (must contain theboundary string).
Parameters:
  dir - the directory to create the files in. an array of name/value pairs, one for each part;the name is the 'name' attribute given in theContent-Disposition header; the value is eitherthe name of the file if a filename attribute wasfound, or the contents of the part.
exception:
  IOException - If any file operation fails.
exception:
  ParseException - If an error during parsing occurs.
See Also:   Codecs.mpFormDataDecode(byte[],java.lang.String,java.lang.String,HTTPClient.FilenameMangler)



mpFormDataDecode
final public static NVPair[] mpFormDataDecode(byte[] data, String cont_type, String dir, FilenameMangler mangler) throws IOException, ParseException(Code)
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).

Examples: If you're receiving a multipart/form-data encoded response from a server you could use something like:

 NVPair[] opts = Codecs.mpFormDataDecode(resp.getData(),
 resp.getHeader("Content-type"), ".");
 
If you're using this in a Servlet to decode the body of a request from a client you could use something like:
 byte[] body = new byte[req.getContentLength()];
 new DataInputStream(req.getInputStream()).readFully(body);
 NVPair[] opts = Codecs.mpFormDataDecode(body, req.getContentType(),
 ".");
 
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.
Parameters:
  cont_type - the content type header (must contain theboundary string).
Parameters:
  dir - the directory to create the files in.
Parameters:
  mangler - the filename mangler, or null if no mangling isto be done. This is invoked just before eachfile is created and written, thereby allowingyou to control the names of the files. an array of name/value pairs, one for each part;the name is the 'name' attribute given in theContent-Disposition header; the value is eitherthe name of the file if a filename attribute wasfound, or the contents of the part.
exception:
  IOException - If any file operation fails.
exception:
  ParseException - If an error during parsing occurs.



mpFormDataEncode
final public static byte[] mpFormDataEncode(NVPair[] opts, NVPair[] files, NVPair[] cont_type) throws IOException(Code)
This method encodes name/value pairs and files into a byte array using the multipart/form-data encoding.
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.
Parameters:
  files - the files to encode (may be null); for eachNVPair the name refers to the 'name' attributeto be used in the header of the part, and thevalue is the actual filename (the file will beread and it's contents put in the body of thatpart).
Parameters:
  cont_type - this returns a new NVPair in the 0'th elementwhich containsname = "Content-Type",value = "multipart/form-data; boundary=..."(the reason this parameter is an array isbecause a) that's the only way to simulatepass-by-reference and b) you need an array forthe headers parameter to the Post() or Put()anyway). an encoded byte array containing all the optsand files.
exception:
  IOException - If any file operation fails.
See Also:   Codecs.mpFormDataEncode(HTTPClient.NVPair[],HTTPClient.NVPair[],HTTPClient.NVPair[],HTTPClient.FilenameMangler)



mpFormDataEncode
final public static byte[] mpFormDataEncode(NVPair[] opts, NVPair[] files, NVPair[] cont_type, FilenameMangler mangler) throws IOException(Code)
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.
Parameters:
  files - the files to encode (may be null); for eachNVPair the name refers to the 'name' attributeto be used in the header of the part, and thevalue is the actual filename (the file will beread and it's contents put in the body of thatpart).
Parameters:
  cont_type - this returns a new NVPair in the 0'th elementwhich containsname = "Content-Type",value = "multipart/form-data; boundary=..."(the reason this parameter is an array isbecause a) that's the only way to simulatepass-by-reference and b) you need an array forthe headers parameter to the Post() or Put()anyway).
Parameters:
  mangler - the filename mangler, or null if no mangling isto be done. This allows you to change the nameused in the filename attribute of theContent-Disposition header. Note: the manglerwill be invoked twice for each filename. an encoded byte array containing all the optsand files.
exception:
  IOException - If any file operation fails.



nv2query
final public static String nv2query(NVPair pairs)(Code)
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 a string containg the encoded name/value pairs



query2nv
final public static NVPair[] query2nv(String query) throws ParseException(Code)
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 an array of NVPairs
exception:
  ParseException - If the '=' is missing in any field, or ifthe urldecoding of the name or value fails



quotedPrintableDecode
final public static String quotedPrintableDecode(String str) throws ParseException(Code)
This method does a quoted-printable decoding of the given string according to RFC-2045 (Section 6.7). Note: this method expects the whole message in one chunk, not line by line.
Parameters:
  str - the message the decoded message
exception:
  ParseException - If a '=' is not followed by a valid2-digit hex number or '\r\n'.



quotedPrintableEncode
final public static String quotedPrintableEncode(String str)(Code)
This method does a quoted-printable encoding of the given string according to RFC-2045 (Section 6.7). Note: this assumes 8-bit characters.
Parameters:
  str - the string the quoted-printable encoded string



uudecode
final public static byte[] uudecode(char[] data)(Code)
This method decodes the given uuencoded char[].

Note: just the actual data is decoded; any 'begin' and 'end' lines such as those generated by the unix uuencode utility must not be included.
Parameters:
  data - the uuencode-encoded data. the decoded data.




uuencode
final public static char[] uuencode(byte[] data)(Code)
This method encodes the given byte[] using the unix uuencode encding. The output is split into lines starting with the encoded number of encoded octets in the line and ending with a newline. No line is longer than 45 octets (60 characters), not including length and newline.

Note: just the raw data is encoded; no 'begin' and 'end' lines are added as is done by the unix uuencode utility.
Parameters:
  data - the data the uuencoded data




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.