add NetUtil.isopen

This commit is contained in:
Looly
2020-04-19 09:38:17 +08:00
parent eaf1938433
commit f4fc97f9de
5 changed files with 56 additions and 6 deletions

View File

@@ -714,12 +714,29 @@ public class NetUtil {
* @return cookie字符串
* @since 5.2.6
*/
public static List<HttpCookie> parseCookies(String cookieStr){
if(StrUtil.isBlank(cookieStr)){
public static List<HttpCookie> parseCookies(String cookieStr) {
if (StrUtil.isBlank(cookieStr)) {
return Collections.emptyList();
}
return HttpCookie.parse(cookieStr);
}
/**
* 检查远程端口是否开启
*
* @param address 远程地址
* @param timeout 检测超时
* @return 远程端口是否开启
* @since 5.3.2
*/
public static boolean isOpen(InetSocketAddress address, int timeout) {
try (Socket sc = new Socket()){
sc.connect(address, timeout);
return true;
} catch (Exception e) {
return false;
}
}
// ----------------------------------------------------------------------------------------- Private method start
/**