List of usage examples for java.net URISyntaxException getIndex
public int getIndex()
From source file:com.chigix.bio.proxy.buffer.FixedBufferTest.java
License:asdf
@Test public void testURI() { try {/* ww w. ja v a2 s . c om*/ URI uri = new URI( "http://www.baidu.com/awefawgwage/awefwfa/wefafwef/awdfa?safwefawf=awefaf&afwef=fafwef"); System.out.println(uri.getScheme()); System.out.println(uri.getHost()); System.out.println(uri.getPort()); System.out.println(uri.getQuery()); System.out.println(uri.getPath()); } catch (URISyntaxException ex) { Logger.getLogger(FixedBufferTest.class.getName()).log(Level.SEVERE, null, ex); } String illegalQuery = "http://sclick.baidu.com/w.gif?q=a&fm=se&T=1423492890&y=55DFFF7F&rsv_cache=0&rsv_pre=0&rsv_reh=109_130_149_109_85_195_85_85_85_85|540&rsv_scr=1899_1720_0_0_1080_1920&rsv_sid=10383_1469_12498_10902_11101_11399_11277_11241_11401_12550_11243_11403_12470&cid=0&qid=fd67eec000006821&t=1423492880700&rsv_iorr=1&rsv_tn=baidu&path=http%3A%2F%2Fwww.baidu.com%2Fs%3Fie%3Dutf-8%26f%3D8%26rsv_bp%3D1%26rsv_idx%3D1%26ch%3D%26tn%3Dbaidu%26bar%3D%26wd%3Da%26rn%3D%26rsv_pq%3Dda7dc5fb00004904%26rsv_t%3D55188AMIFp8JX4Jb3hJkfCZHYxQdZOBK%252FhV0kLFfAPijGGrceXBoFpnHzmI%26rsv_enter%3D1%26inputT%3D111"; URI uri; while (true) { try { uri = new URI(illegalQuery); } catch (URISyntaxException ex) { System.out.println(illegalQuery); System.out.println(illegalQuery.charAt(ex.getIndex())); System.out.println(illegalQuery.substring(0, ex.getIndex())); System.out.println(illegalQuery.substring(ex.getIndex() + 1)); try { illegalQuery = illegalQuery.substring(0, ex.getIndex()) + URLEncoder.encode(String.valueOf(illegalQuery.charAt(ex.getIndex())), "utf-8") + illegalQuery.substring(ex.getIndex() + 1); } catch (UnsupportedEncodingException ex1) { } System.out.println(illegalQuery); continue; } break; } System.out.println("SCHEME: " + uri.getScheme()); System.out.println("HOST: " + uri.getHost()); System.out.println("path: " + uri.getRawPath()); System.out.println("query: " + uri.getRawQuery()); System.out.println("PORT: " + uri.getPort()); }