forked from aofeng/JavaTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineEncoder.java
More file actions
31 lines (24 loc) · 876 Bytes
/
LineEncoder.java
File metadata and controls
31 lines (24 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package cn.aofeng.demo.reactor;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* 将字符串转换成{@link ByteBuffer}并加上行结束符。
*
* @author <a href="mailto:aofengblog@163.com">NieYong </a>
*/
public class LineEncoder implements Encoder {
private final static Logger logger = Logger.getLogger(LineEncoder.class.getName());
@Override
public ByteBuffer encode(Object source) {
String line = (String) source;
try {
ByteBuffer buffer = ByteBuffer.wrap(line.getBytes(Constant.CHARSET_UTF8));
return buffer;
} catch (UnsupportedEncodingException e) {
logger.log(Level.SEVERE, "将响应数据转换成ByteBuffer出错", e);
}
return null;
}
}