mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-03 04:13:49 +08:00
add closeable
This commit is contained in:
parent
96e377f414
commit
3288f26795
@ -18,6 +18,7 @@
|
||||
* 【http】 HttpRequest增加setChunkedStreamingMode方法(issue#525@Github)
|
||||
* 【setting】 SettingLoader支持自定义分隔符
|
||||
* 【http】 Content-Type添加默认值(issue#I11YHI@Gitee)
|
||||
* 【socket】 增加Closeable接口(issue#532@Github)
|
||||
|
||||
### Bug修复
|
||||
* 【core】 修复NetUtil.getUsableLocalPort问题(pr#69@Gitee)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.socket.aio;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketOption;
|
||||
@ -19,7 +20,7 @@ import cn.hutool.socket.SocketRuntimeException;
|
||||
* @author looly
|
||||
* @since 4.5.0
|
||||
*/
|
||||
public class AioClient {
|
||||
public class AioClient implements Closeable{
|
||||
|
||||
private AioSession session;
|
||||
|
||||
@ -102,6 +103,7 @@ public class AioClient {
|
||||
/**
|
||||
* 关闭客户端
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
this.session.close();
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.socket.aio;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketOption;
|
||||
@ -21,7 +22,7 @@ import cn.hutool.socket.SocketConfig;
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class AioServer {
|
||||
public class AioServer implements Closeable{
|
||||
private static final Log log = LogFactory.get();
|
||||
private static AcceptHandler ACCEPT_HANDLER = new AcceptHandler();
|
||||
|
||||
@ -148,6 +149,7 @@ public class AioServer {
|
||||
/**
|
||||
* 关闭服务
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
IoUtil.close(this.channel);
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.socket.aio;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
@ -20,7 +21,7 @@ import cn.hutool.socket.SocketUtil;
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class AioSession {
|
||||
public class AioSession implements Closeable{
|
||||
|
||||
private static final ReadHandler READ_HANDLER = new ReadHandler();
|
||||
|
||||
@ -190,6 +191,7 @@ public class AioSession {
|
||||
/**
|
||||
* 关闭会话
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
IoUtil.close(this.channel);
|
||||
this.readBuffer = null;
|
||||
|
@ -1,11 +1,13 @@
|
||||
package cn.hutool.socket.nio;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
|
||||
/**
|
||||
* NIO客户端
|
||||
@ -13,7 +15,7 @@ import cn.hutool.core.io.IORuntimeException;
|
||||
* @author looly
|
||||
* @since 4.4.5
|
||||
*/
|
||||
public class NioClient {
|
||||
public class NioClient implements Closeable{
|
||||
|
||||
private SocketChannel channel;
|
||||
|
||||
@ -80,4 +82,9 @@ public class NioClient {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
IoUtil.close(this.channel);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ public class AioServerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
AioServer aioServer = new AioServer(8899);
|
||||
aioServer.setIoAction(new SimpleIoAction() {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user