Package org.bzdev.net

Class WebDecoder

java.lang.Object
org.bzdev.net.WebDecoder

public class WebDecoder extends Object
Decoder for HTML and Javascript strings.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Map<String,String>
    Read an input stream containing application/x-www-form-encoded data, given a default charset (UTF-8) and an ampersand as the separator between keyword-value pairs, and create a keyword-value map, supporting a single value per key.
    static Map<String,String>
    formDecode(InputStream is, boolean semicolonDelimiter)
    Read an input stream containing application/x-www-form-encoded data, given a default charset (UTF-8), and create a keyword-value map, supporting a single value per key.
    static Map<String,String>
    formDecode(InputStream is, boolean semicolonDelimiter, Charset charset)
    Read an input stream containing application/x-www-form-encoded data, given a charset, and create a keyword-value map, supporting a single value per key.
    static Map<String,String>
    Convert a string containing application/x-www-form-encoded data, given a default charset (UTF-8) and an ampersand as the separator between keyword-value pairs, and create a keyword-value map, supporting a single value per key.
    static Map<String,String>
    formDecode(String string, boolean semicolonDelimiter)
    Convert a string containing application/x-www-form-encoded data, given a default charset (UTF-8), and create a keyword-value map, supporting a single value per key.
    static Map<String,String>
    formDecode(String string, boolean semicolonDelimiter, Charset charset)
    Convert a string containing application/x-www-form-encoded data, given a charset, and create a keyword-value map, supporting a single value per key.
    static Map<String,String[]>
    Read an input stream containing application/x-www-form-encoded data, given a default charset (UTF-8) and an ampersand as the separator between keyword-value pairs, and create a keyword-value map, supporting multiple values per key.
    static Map<String,String[]>
    formDecodeMV(InputStream is, boolean semicolonDelimiter)
    Read an input stream containing application/x-www-form-encoded data, given a default charset (UTF-8), and create a keyword-value map, supporting multiple values per key.
    static Map<String,String[]>
    formDecodeMV(InputStream is, boolean semicolonDelimiter, Charset charset)
    Read an input stream containing application/x-www-form-encoded data, given a charset, and create a keyword-value map, supporting multiple values per key.
    static Map<String,String[]>
    Convert a string containing application/x-www-form-encoded data, given a default charset (UTF-8) and an ampersand as the separator between keyword-value pairs, and create a keyword-value map, supporting a multiple values per key.
    static Map<String,String[]>
    formDecodeMV(String string, boolean semicolonDelimiter)
    Convert a string containing application/x-www-form-encoded data, given a default charset (UTF-8), and create a keyword-value map, supporting a multiple values per key.
    static Map<String,String[]>
    formDecodeMV(String string, boolean semicolonDelimiter, Charset charset)
    Convert a string containing application/x-www-form-encoded data, given a charset, and create a keyword-value map, supporting multiple values per key.
    static String
    Decode an HTML-encoded string.
    static String
    Decode a string that is encoded so that it can appear within double quotes in a Java or ECMAScript program.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WebDecoder

      public WebDecoder()
  • Method Details

    • htmlDecode

      public static String htmlDecode(String string) throws IllegalArgumentException
      Decode an HTML-encoded string. The entities '&amp;', '&quote;', '&gt;' and '&lt;' are replaced with '&', '"', '>' and '<' respectively.
      Parameters:
      string - the input string
      Returns:
      the decoded string; null if the input string is null
      Throws:
      IllegalArgumentException - there is a syntax error in the argument
    • quoteDecode

      public static String quoteDecode(String string) throws IllegalArgumentException
      Decode a string that is encoded so that it can appear within double quotes in a Java or ECMAScript program. This method replaces escape sequences with their corresponding characters. The argument does not include the delimiting quotes that would appear in Java or ECMA code.
      Parameters:
      string - the string to decode
      Returns:
      the decoded string.
      Throws:
      IllegalArgumentException - there is a syntax error in the argument
    • formDecode

      public static Map<String,String> formDecode(String string) throws IllegalArgumentException
      Convert a string containing application/x-www-form-encoded data, given a default charset (UTF-8) and an ampersand as the separator between keyword-value pairs, and create a keyword-value map, supporting a single value per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      string - a String containing the URL-encoded data
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IllegalArgumentException
    • formDecodeMV

      public static Map<String,String[]> formDecodeMV(String string) throws IllegalArgumentException
      Convert a string containing application/x-www-form-encoded data, given a default charset (UTF-8) and an ampersand as the separator between keyword-value pairs, and create a keyword-value map, supporting a multiple values per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      string - a String containing the URL-encoded data
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IllegalArgumentException
    • formDecode

      public static Map<String,String> formDecode(String string, boolean semicolonDelimiter) throws IllegalArgumentException
      Convert a string containing application/x-www-form-encoded data, given a default charset (UTF-8), and create a keyword-value map, supporting a single value per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      string - a String containing the URL-encoded data
      semicolonDelimiter - true if the delimiter should be a semicolon (";") rather than an ampersand ("&").
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IllegalArgumentException
    • formDecodeMV

      public static Map<String,String[]> formDecodeMV(String string, boolean semicolonDelimiter) throws IllegalArgumentException
      Convert a string containing application/x-www-form-encoded data, given a default charset (UTF-8), and create a keyword-value map, supporting a multiple values per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      string - a String containing the URL-encoded data
      semicolonDelimiter - true if the delimiter should be a semicolon (";") rather than an ampersand ("&").
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IllegalArgumentException
    • formDecode

      public static Map<String,String> formDecode(String string, boolean semicolonDelimiter, Charset charset) throws IllegalArgumentException
      Convert a string containing application/x-www-form-encoded data, given a charset, and create a keyword-value map, supporting a single value per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      string - a String containing the URL-encoded data
      semicolonDelimiter - true if the delimiter should be a semicolon (";") rather than an ampersand ("&").
      charset - the Charset used when the keyword-value pairs was encoded
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IllegalArgumentException
    • formDecodeMV

      public static Map<String,String[]> formDecodeMV(String string, boolean semicolonDelimiter, Charset charset) throws IllegalArgumentException
      Convert a string containing application/x-www-form-encoded data, given a charset, and create a keyword-value map, supporting multiple values per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument, based on the first occurrence of a key.
      Parameters:
      string - a String containing the URL-encoded data
      semicolonDelimiter - true if the delimiter should be a semicolon (";") rather than an ampersand ("&").
      charset - the Charset used when the keyword-value pairs was encoded
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IllegalArgumentException
    • formDecode

      public static Map<String,String> formDecode(InputStream is) throws IllegalArgumentException, IOException
      Read an input stream containing application/x-www-form-encoded data, given a default charset (UTF-8) and an ampersand as the separator between keyword-value pairs, and create a keyword-value map, supporting a single value per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      is - the input stream
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IOException - an IO error occurred, including syntax errors in the input stream
      IllegalArgumentException
    • formDecodeMV

      public static Map<String,String[]> formDecodeMV(InputStream is) throws IllegalArgumentException, IOException
      Read an input stream containing application/x-www-form-encoded data, given a default charset (UTF-8) and an ampersand as the separator between keyword-value pairs, and create a keyword-value map, supporting multiple values per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      is - the input stream
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IOException - an IO error occurred, including syntax errors in the input stream
      IllegalArgumentException
    • formDecode

      public static Map<String,String> formDecode(InputStream is, boolean semicolonDelimiter) throws IllegalArgumentException, IOException
      Read an input stream containing application/x-www-form-encoded data, given a default charset (UTF-8), and create a keyword-value map, supporting a single value per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      is - the input stream
      semicolonDelimiter - true if the delimiter should be a semicolon (";") rather than an ampersand ("&").
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IOException - an IO error occurred, including syntax errors in the input stream
      IllegalArgumentException
    • formDecodeMV

      public static Map<String,String[]> formDecodeMV(InputStream is, boolean semicolonDelimiter) throws IllegalArgumentException, IOException
      Read an input stream containing application/x-www-form-encoded data, given a default charset (UTF-8), and create a keyword-value map, supporting multiple values per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      is - the input stream
      semicolonDelimiter - true if the delimiter should be a semicolon (";") rather than an ampersand ("&").
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IOException - an IO error occurred, including syntax errors in the input stream
      IllegalArgumentException
    • formDecode

      public static Map<String,String> formDecode(InputStream is, boolean semicolonDelimiter, Charset charset) throws IllegalArgumentException, IOException
      Read an input stream containing application/x-www-form-encoded data, given a charset, and create a keyword-value map, supporting a single value per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      is - the input stream
      semicolonDelimiter - true if the delimiter should be a semicolon (";") rather than an ampersand ("&").
      charset - the Charset used when the keyword-value pairs was encoded
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IOException - an IO error occurred, including syntax errors in the input stream
      IllegalArgumentException
    • formDecodeMV

      public static Map<String,String[]> formDecodeMV(InputStream is, boolean semicolonDelimiter, Charset charset) throws IllegalArgumentException, IOException
      Read an input stream containing application/x-www-form-encoded data, given a charset, and create a keyword-value map, supporting multiple values per key. The map's iterator will provide entries in the same order as the keyword-value pairs in the argument.
      Parameters:
      is - the input stream
      semicolonDelimiter - true if the delimiter should be a semicolon (";") rather than an ampersand ("&").
      charset - the Charset used when the keyword-value pairs was encoded
      Returns:
      a the map of keyword-value pairs (both elements are strings)
      Throws:
      IOException - an IO error occurred, including syntax errors in the input stream
      IllegalArgumentException