mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add NetUtil.isopen
This commit is contained in:
parent
eaf1938433
commit
f4fc97f9de
@ -3,10 +3,12 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
## 5.3.2 (2020-04-17)
|
## 5.3.2 (2020-04-19)
|
||||||
|
|
||||||
### 新特性
|
### 新特性
|
||||||
|
* 【core 】 增加NetUtil.isOpen方法
|
||||||
### Bug修复
|
### Bug修复
|
||||||
|
* 【db 】 修复PageResult.isLast计算问题
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
## 5.3.1 (2020-04-17)
|
## 5.3.1 (2020-04-17)
|
||||||
|
@ -714,12 +714,29 @@ public class NetUtil {
|
|||||||
* @return cookie字符串
|
* @return cookie字符串
|
||||||
* @since 5.2.6
|
* @since 5.2.6
|
||||||
*/
|
*/
|
||||||
public static List<HttpCookie> parseCookies(String cookieStr){
|
public static List<HttpCookie> parseCookies(String cookieStr) {
|
||||||
if(StrUtil.isBlank(cookieStr)){
|
if (StrUtil.isBlank(cookieStr)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
return HttpCookie.parse(cookieStr);
|
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
|
// ----------------------------------------------------------------------------------------- Private method start
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package cn.hutool.db;
|
package cn.hutool.db;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.PageUtil;
|
import cn.hutool.core.util.PageUtil;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页数据结果集
|
* 分页数据结果集
|
||||||
*
|
*
|
||||||
@ -169,6 +169,6 @@ public class PageResult<T> extends ArrayList<T> {
|
|||||||
* @return 是否最后一页
|
* @return 是否最后一页
|
||||||
*/
|
*/
|
||||||
public boolean isLast() {
|
public boolean isLast() {
|
||||||
return this.page >= this.totalPage;
|
return this.page >= (this.totalPage - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
hutool-db/src/test/java/cn/hutool/db/PageResultTest.java
Normal file
14
hutool-db/src/test/java/cn/hutool/db/PageResultTest.java
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
@ -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/");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user