Rewrite of URI parsing because standard Java URI cannot handle the malformed URLs that appear in real life.