Class pmr.util.Codecs
All Packages Class Hierarchy This Package Previous Next Index
Class pmr.util.Codecs
java.lang.Object
|
+----pmr.util.Codecs
- public class Codecs
- extends Object
This class collects various encoders and decoders.
- Author:
- Ronald Tschalär
-
base64Decode(byte[])
- This method decodes the given byte[] using the base64-encoding
specified in RFC-1521.
-
base64Decode(String)
- This method decodes the given string using the base64-encoding
specified in RFC-1521.
-
base64Encode(byte[])
- This method encodes the given byte[] using the base64-encoding
specified in RFC-1521.
-
base64Encode(String)
- This method encodes the given string using the base64-encoding
specified in RFC-1521.
-
chunkedDecode(InputStream)
- Decodes chunked data.
-
chunkedEncode(byte[], NVPair[], boolean)
- Encodes data used the chunked encoding.
-
getParameter(String, String)
- retrieves the value associated with the parameter param in
a given header string.
-
mpFormDataDecode(byte[], String, String)
- This method decodes a multipart/form-data encoded string.
-
mpFormDataEncode(NVPair[], NVPair[], NVPair)
- This method encodes name/value pairs and files into a byte array
using the multipart/form-data encoding.
-
nv2query(NVPair[])
- Turns an array of name/value pairs into the string
"name1=value1&name2=value2&name3=value3".
-
query2nv(String)
- Turns a string of the form "name1=value1&name2=value2&name3=value3"
into an array of name/value pairs.
-
quotedPrintableDecode(String)
- This method does a quoted-printable decoding of the given string
according to RFC-1521.
-
quotedPrintableEncode(String)
- This method does a quoted-printable encoding of the given string
according to RFC-1521.
-
readBase64(InputStream)
- reads an input stream and translates the characters into a byte array
-
URLDecode(String)
- This method decodes the given urlencoded string.
-
URLEncode(String)
- This method urlencodes the given string.
-
writeBase64(byte[], OutputStream)
- writes a byte array as ASCII characters to an output stream
writeBase64
public static void writeBase64(byte b64[],
OutputStream os) throws IOException
- writes a byte array as ASCII characters to an output stream
readBase64
public static byte[] readBase64(InputStream is) throws IOException
- reads an input stream and translates the characters into a byte array
base64Encode
public final static String base64Encode(String str)
- This method encodes the given string using the base64-encoding
specified in RFC-1521. It's used for example in the "basic"
authorization scheme.
- Parameters:
- str - the string
- Returns:
- the base64-encoded str
base64Encode
public final static byte[] base64Encode(byte data[])
- This method encodes the given byte[] using the base64-encoding
specified in RFC-1521.
- Parameters:
- data - the data
- Returns:
- the base64-encoded data
base64Decode
public final static String base64Decode(String str)
- This method decodes the given string using the base64-encoding
specified in RFC-1521.
- Parameters:
- str - the base64-encoded string.
- Returns:
- the decoded str.
base64Decode
public final static byte[] base64Decode(byte data[])
- This method decodes the given byte[] using the base64-encoding
specified in RFC-1521.
- Parameters:
- data - the base64-encoded data.
- Returns:
- the decoded data.
quotedPrintableEncode
public final static String quotedPrintableEncode(String str)
- This method does a quoted-printable encoding of the given string
according to RFC-1521. Note: it assumes 8-bit characters.
- Parameters:
- str - the string
- Returns:
- the quoted-printable encoded string
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.
- 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
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
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
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 variable, 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).
- 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 name/value pairs.
- Throws: IOException
- If any file operation fails.
- Throws: ParseException
- If an error during parsing occurs.
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
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.
- Parameters:
- opts - the simple form-data to encode.
- files - the files to encode.
- cont_type - an empty NVPair. This is filled with
name = "Content-Type",
value = "multipart/form-data; boundary=..."
- Returns:
- an encoded byte array containing all the opts
and files.
- Throws: IOException
- If any file operation fails.
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
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
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
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