Class PostAndUrlReader

java.lang.Object
eu.bandm.tools.util.PostAndUrlReader

public class PostAndUrlReader extends Object
Decodes key/value pairs, as they occur in http connections, and stores them to a map. Two methods are provided, one for "get" url-encoded paremeters, one for "post" parameters which come with the "message body". Both use the same encoding mechanism, which is called "url encoding" by practioneers (because in URLs it is visible !-)

The specification is rfc822.
Encoding is NOT an issue because only ASCII characters are permitted. (0..127, see section 3.1 and 3.3)

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    evident
    static final int
    evident
    protected int
    Buffer for the current character read.
    static final int
    evident
    static final int
    evident
    static final int
    evident
    static final int
    evident
    static final int
    evident
    static final int
    evident
    static final Map<String,String>
    evident
    static final int
    The integer number for "end of input" as produced by InputStream.read().
    static final int
    evident
    protected int
    Counter for maximally read characters.
    protected InputStream
    Source of input.
    static final int
    evident
    static final int
    evident
    static final int
    evident
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    hexdigit(int c)
    Returns the integer value of a hexadecimal digit.
    read(InputStream in, int maxNum)
    Decodes key/value pairs from an http connection message body, as with a "post" method, and stores them to a map.
    protected void
    Read and convert a character in the buffer c.
    protected void
    Read a character from in into the buffer c, as long as number of expected is not reached.
    Decodes key/value pairs from an http connection url value, as with the "get" method, and stores them to a map.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • PostAndUrlReader

      public PostAndUrlReader()
  • Method Details

    • hexdigit

      public static int hexdigit(int c) throws IOException
      Returns the integer value of a hexadecimal digit.
      Throws:
      IOException - if no such.
    • readCC

      protected void readCC() throws IOException
      Read a character from in into the buffer c, as long as number of expected is not reached.
      Throws:
      IOException
    • readC

      protected void readC() throws IOException
      Read and convert a character in the buffer c. A "+" is replaced by a blank " ". A percent sign followed by two hex digits is replaced by the character with that number.
      Throws:
      IOException - if no two hexdigits follow a percent.
    • readUrl

      public Map<String,String> readUrl(String url) throws IOException
      Decodes key/value pairs from an http connection url value, as with the "get" method, and stores them to a map. The url analyzed starting with the first occurence of the lead-in character QUEST. It there is no such occurence, an empty map is returned.
      Throws:
      IOException
    • read

      public Map<String,String> read(InputStream in, int maxNum) throws IOException
      Decodes key/value pairs from an http connection message body, as with a "post" method, and stores them to a map. The format of the text to decode is
        key1=value1&key2=value2&key3=value3
        
      where VW%2aXY can insert one character by two hexadecimal digits.

      The stream must be provided, and the maximum number of octets to be read. When the stream is closed or this number is reached, the map is returned as constructed so far.

      Throws:
      IOException