Skip to content

05. URLUtil

晓寻遥 edited this page Nov 6, 2021 · 1 revision

Introduce

URLUtil is a tool that can complete incomplete URLS.

method

1. url

Introduce

create an object from a URL address in the form of a string.

Example

public void url() throws Exception{
		String a = "https://github.com/xiao-organization/xiaoTools/wiki/2.-StrUtil";
		URL url = URLUtil.url(a);
		// github.com
		System.out.println(url.getAuthority());
}

2. normalize

Introduce

standardize URL links. simply complete the address without the 「http:// header」.

Example

public void test_normalize(){
		String a = "http://github.com//xiao-organization/\\xiaoTools";
		String b = URLUtil.normalize(a);
		// http://github.com//xiao-organization//xiaoTools
		System.out.println(b);
}

3. encode and decode

Introduce

use hexadecimal notation to convert the content that needs to be converted (contents other than the ASCII code form), and add% at the beginning.

Example

public void encode_and_decode(){
		String a = "xiaoTools的图标.jpg";
		String b = URLUtil.encode(a);
		// xiaoTools%E7%9A%84%E5%9B%BE%E6%A0%87.jpg
		System.out.println(b);

		String c = URLUtil.decode(b);
		// xiaoTools的图标.jpg
		System.out.println(c);
}

more

to learn more, refer to the API documentation

Clone this wiki locally