如何以所需格式解析URI

时间:2016-07-14 18:20:12

标签: java parsing

我必须得到从服务器收到的aURL代码中提到的baseUri,我不知道如何解析它,而且到目前为止解析的是有没有办法以更好的方式做到这一点?

aURL="https://assetservice.blob.core.windows.net/org66/6caedd1b-5373-4485-a5ad-8b8a9b5af62c/Input/0b2253b8-ee2a-4c80-a766-146fc139f2c4.hlkx?sv=2013-08-15&sr=b&sig=XXwsBuYidvWrvmE8RbjUgfTKzHhlMaqZNYhnibnJuQM%3D&se=2016-07-13T18%3A18%3A09Z&sp=w"

我必须解析它:

BaseURI="http://stackoverflow.com/questions/34251435/how-to-get-the-new-content-from-the-file/34251504#34251504"

参考代码(我的工作):

 public static void main(String[] args) throws MalformedURLException {
 String Url = "https://assetservice.blob.core.windows.net/org66/89r7egf8drfvhdkjv89f/Input/489578947fkjbgdfkjbnvdfkj.hlkx?sv=2013-08-15&sr=b&sig=kjhgres89g54dkjfhvgrt89gtvhrsp8&se=2016-07-13T18%3A18%3A09Z&sp=w";
 String baseUri="https://assetservice.blob.core.windows.net/org66/89r7egf8drfvhdkjv89f";
 String sas="?sv=2013-08-15&sr=b&sig=kjhgres89g54dkjfhvgrt89gtvhrsp8&se=2016-07-13T18%3A18%3A09Z&sp=w";
 String AbsoluteUri="https://assetservice.blob.core.windows.net/org66/89r7egf8drfvhdkjv89f/Input/489578947fkjbgdfkjbnvdfkj.hlkx";

 URL aURL = new URL("https://assetservice.blob.core.windows.net/org66/6caedd1b-5373-4485-a5ad-8b8a9b5af62c/Input/0b2253b8-ee2a-4c80-a766-146fc139f2c4.hlkx?sv=2013-08-15&sr=b&sig=XXwsBuYidvWrvmE8RbjUgfTKzHhlMaqZNYhnibnJuQM%3D&se=2016-07-13T18%3A18%3A09Z&sp=w");
System.out.println("protocol = " + aURL.getProtocol());
System.out.println("authority = " + aURL.getAuthority());
System.out.println("host = " + aURL.getHost());
System.out.println("port = " + aURL.getPort());
System.out.println("path = " + aURL.getPath());
System.out.println("query = " + aURL.getQuery());
System.out.println("filename = " + aURL.getFile());
System.out.println("ref = " + aURL.getRef());

System.out.println("AbsoluteURI---------------->"+aURL.getProtocol()+"://"+aURL.getHost()+aURL.getPath());
System.out.println("Sas------------------------->"+"?"+aURL.getQuery());
System.out.println("BaseUrI-------------------------->");
}

结果:

protocol = https
authority = assetservice.blob.core.windows.net
host = assetservice.blob.core.windows.net
port = -1
path = /org66/6caedd1b-5373-4485-a5ad-8b8a9b5af62c/Input/0b2253b8-ee2a-4c80-a766-146fc139f2c4.hlkx
query = sv=2013-08-15&sr=b&sig=XXwsBuYidvWrvmE8RbjUgfTKzHhlMaqZNYhnibnJuQM%3D&se=2016-07-13T18%3A18%3A09Z&sp=w
filename = /org66/6caedd1b-5373-4485-a5ad-8b8a9b5af62c/Input/0b2253b8-ee2a-4c80-a766-146fc139f2c4.hlkx?sv=2013-08-15&sr=b&sig=XXwsBuYidvWrvmE8RbjUgfTKzHhlMaqZNYhnibnJuQM%3D&se=2016-07-13T18%3A18%3A09Z&sp=w
ref = null
AbsoluteURI---------------->https://assetservice.blob.core.windows.net/org66/6caedd1b-5373-4485-a5ad-8b8a9b5af62c/Input/0b2253b8-ee2a-4c80-a766-146fc139f2c4.hlkx
Sas------------------------->?sv=2013-08-15&sr=b&sig=XXwsBuYidvWrvmE8RbjUgfTKzHhlMaqZNYhnibnJuQM%3D&se=2016-07-13T18%3A18%3A09Z&sp=w

0 个答案:

没有答案