public class XmlDecoder extends Object
The usage is as the following:
使用方法如下:
and then you can use aChannelPipelinepipeline = ...; // construct a decoder XmlDecoder xmlDecoder = new XmlDecoder( 10000, // maximum length of the XML messages "env:Envelope", // top level tag of the XML messages CharsetUtil.UTF_8); // character encoding of the messages // setup the pipeline to use the decoder pipeline.addLast("frameDecoder", xmlDecoder.getFrameDecoder()); pipeline.addLast("stringDecoder", xmlDecoder.getStringDecoder());
String instead of a ChannelBuffer
when processing messages:
void messageReceived(ChannelHandlerContextctx,MessageEvente) { String msg = (String) e.getMessage(); System.out.print("The XML body is '" + msg + "'\n"); }
| Modifier and Type | Class and Description |
|---|---|
protected static class |
XmlDecoder.XmlStringDecoder
Further process the messages already processed by
FrameDecoder to make it clean XML text messages.
把经过FrameDecoder处理过后的消息,进一步加工为头尾完整干净的XML文本。 |
| Modifier and Type | Field and Description |
|---|---|
protected static byte[] |
endTagEndingByte |
protected org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder |
frameDecoder |
protected static char[] |
startTagEndingChar |
protected XmlDecoder.XmlStringDecoder |
stringDecoder |
| Constructor and Description |
|---|
XmlDecoder(int maxFrameLength,
String topLevelTagName,
Charset charset)
Constructor after which both its
getFrameDecoder() and getStringDecoder() methods should be
called to get two decoders for Netty.创建一个实例,创建好之后,它的 getFrameDecoder()方法和getStringDecoder()方法都应该被调用
以获得给Netty用的两个decoder。 |
| Modifier and Type | Method and Description |
|---|---|
protected org.jboss.netty.buffer.ChannelBuffer[] |
buildDelimiters(String tagName,
Charset charset)
Creates delimiters that will be used to construct
DelimiterBasedFrameDecoder.根据XML标签的名称,生成适合 DelimiterBasedFrameDecoder用的delimiters。 |
org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder |
getFrameDecoder()
Get the frame decoder to be used by Netty.
获得给Netty用的frame decoder。 |
org.jboss.netty.handler.codec.oneone.OneToOneDecoder |
getStringDecoder()
Get the string decoder to be used by Netty.
获得给Netty用的string decoder。 |
protected static char[] startTagEndingChar
protected static byte[] endTagEndingByte
protected org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder frameDecoder
protected XmlDecoder.XmlStringDecoder stringDecoder
public XmlDecoder(int maxFrameLength,
String topLevelTagName,
Charset charset)
getFrameDecoder() and getStringDecoder() methods should be
called to get two decoders for Netty.getFrameDecoder()方法和getStringDecoder()方法都应该被调用
以获得给Netty用的两个decoder。maxFrameLength - Maximum length of XML text messages that might be received.topLevelTagName - Top level XML tag that marks the beginning and ending of XML messages.charset - Character set that the text messages are encoded in.protected org.jboss.netty.buffer.ChannelBuffer[] buildDelimiters(String tagName, Charset charset)
DelimiterBasedFrameDecoder.DelimiterBasedFrameDecoder用的delimiters。tagName - Name of the top level XML tag (not including <, /, etc).charset - Character set encoding of the messages to be processed.public org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder getFrameDecoder()
Always use this method together with getStringDecoder().
这个方法总是与getStringDecoder()方法结合起来一起用。
public org.jboss.netty.handler.codec.oneone.OneToOneDecoder getStringDecoder()
Always use this method together with getFrameDecoder().
这个方法总是与getFrameDecoder()方法结合起来一起用。
Copyright © 2014. All Rights Reserved.