mirror of
https://github.com/Estom/notes.git
synced 2026-02-07 20:44:38 +08:00
Java内容重新整理删除过期的东西
This commit is contained in:
41
Java/JavaDemo/codedemo/reactor/Writer.java
Normal file
41
Java/JavaDemo/codedemo/reactor/Writer.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package cn.aofeng.demo.reactor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
/**
|
||||
* 负责向客户端发送响应数据。
|
||||
*
|
||||
* @author <a href="mailto:aofengblog@163.com">NieYong </a>
|
||||
*/
|
||||
public class Writer {
|
||||
|
||||
private SocketChannel _clientChannel;
|
||||
|
||||
private Object _data;
|
||||
|
||||
private Encoder _encoder;
|
||||
|
||||
public Writer(SocketChannel clientChannel, Object data) {
|
||||
this._clientChannel = clientChannel;
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
public void setEncoder(Encoder encoder) {
|
||||
this._encoder = encoder;
|
||||
}
|
||||
|
||||
public void write() throws IOException {
|
||||
if (null == _data || !_clientChannel.isOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuffer buffer = _encoder.encode(_data);
|
||||
if (null == buffer) {
|
||||
return;
|
||||
}
|
||||
_clientChannel.write(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user