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

@ -3,10 +3,12 @@
-------------------------------------------------------------------------------------------------------------
## 5.3.2 (2020-04-17)
## 5.3.2 (2020-04-19)
### 新特性
* 【core 】 增加NetUtil.isOpen方法
### Bug修复
* 【db 】 修复PageResult.isLast计算问题
-------------------------------------------------------------------------------------------------------------
## 5.3.1 (2020-04-17)

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
/**

View File

@ -1,9 +1,9 @@
package cn.hutool.db;
import java.util.ArrayList;
import cn.hutool.core.util.PageUtil;
import java.util.ArrayList;
/**
* 分页数据结果集
*
@ -169,6 +169,6 @@ public class PageResult<T> extends ArrayList<T> {
* @return 是否最后一页
*/
public boolean isLast() {
return this.page >= this.totalPage;
return this.page >= (this.totalPage - 1);
}
}

View File

@ -0,0 +1,14 @@
package cn.hutool.db;
import org.junit.Assert;
import org.junit.Test;
public class PageResultTest {
@Test
public void isLastTest(){
// 每页2条共10条总共5页第一页是0最后一页应该是4
final PageResult<String> result = new PageResult<>(4, 2, 10);
Assert.assertTrue(result.isLast());
}
}

View File

@ -0,0 +1,17 @@
package cn.hutool.http.server;
import cn.hutool.core.swing.DesktopUtil;
import cn.hutool.http.HttpUtil;
public class DocServerTest {
public static void main(String[] args) {
HttpUtil.createServer(80)
// 设置默认根目录
.setRoot("D:\\workspace\\site\\hutool-site")
// 返回JSON数据测试
.start();
DesktopUtil.browse("http://localhost/");
}
}