title: Decoding URI query string in Java
body: <p>I need to decode a URI that contains a query string; expected input/output behavior is something like the following:</p>
  
  <pre><code>abstract class URIParser
  {       
      /** example input: 
        * something?alias=pos&amp;FirstName=Foo+A%26B%3DC&amp;LastName=Bar */
      URIParser(String input) { ... }
      /** should return "something" for the example input */
      public String getPath(); 
      /** should return a map 
        * {alias: "pos", FirstName: "Foo+A&amp;B=C", LastName: "Bar"} */
      public Map&lt;String,String&gt; getQuery();
  }
  </code></pre>
  
  <p>I've tried using <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html" rel="noreferrer">java.net.URI</a>, but it seems to decode the query string so in the above example I'm left with "alias=pos&amp;FirstName=Foo+A&amp;B=C&amp;LastName=Bar" so there is ambiguity whether a "&amp;" is a query separator or is a character in a query component.</p>
  
  <p><strong>Edit:</strong> I just tried <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URI.html#getRawQuery%28%29" rel="noreferrer">URI.getRawQuery()</a> and it doesn't do the encoding, so I can split the query string with a <code>&amp;</code>, but then what do I do? Javascript has <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Functions/decodeURIComponent" rel="noreferrer">decodeURIComponent</a>, I can't seem to find the corresponding method in Java.</p>
  
  <p>Any suggestions? I would prefer not to use any new libraries.</p>