本文整理汇总了Java中io.netty.handler.codec.ByteToMessageDecoder类的典型用法代码示例。如果您正苦于以下问题:Java ByteToMessageDecoder类的具体用法?Java ByteToMessageDecoder怎么用?Java ByteToMessageDecoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteToMessageDecoder类属于io.netty.handler.codec包,在下文中一共展示了ByteToMessageDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initChannel
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
UserConnection info = new UserConnection(socketChannel);
// init protocol
new ProtocolPipeline(info);
// Add originals
this.method.invoke(this.original, socketChannel);
HandlerConstructor constructor = ClassGenerator.getConstructor();
// Add our transformers
MessageToByteEncoder encoder = constructor.newEncodeHandler(info, (MessageToByteEncoder) socketChannel.pipeline().get("encoder"));
ByteToMessageDecoder decoder = constructor.newDecodeHandler(info, (ByteToMessageDecoder) socketChannel.pipeline().get("decoder"));
BukkitPacketHandler chunkHandler = new BukkitPacketHandler(info);
socketChannel.pipeline().replace("encoder", "encoder", encoder);
socketChannel.pipeline().replace("decoder", "decoder", decoder);
socketChannel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler);
}
示例2: initChannel
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel socketChannel) throws Exception {
// Ensure ViaVersion is loaded
if (ProtocolRegistry.SERVER_PROTOCOL != -1) {
UserConnection info = new UserConnection(socketChannel);
// init protocol
new ProtocolPipeline(info);
// Add originals
this.method.invoke(this.original, socketChannel);
// Add our transformers
MessageToByteEncoder encoder = new SpongeEncodeHandler(info, (MessageToByteEncoder) socketChannel.pipeline().get("encoder"));
ByteToMessageDecoder decoder = new SpongeDecodeHandler(info, (ByteToMessageDecoder) socketChannel.pipeline().get("decoder"));
SpongePacketHandler chunkHandler = new SpongePacketHandler(info);
socketChannel.pipeline().replace("encoder", "encoder", encoder);
socketChannel.pipeline().replace("decoder", "decoder", decoder);
socketChannel.pipeline().addAfter("packet_handler", "viaversion_packet_handler", chunkHandler);
} else {
this.method.invoke(this.original, socketChannel);
}
}
示例3: autoAddHttpExtractor
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
static void autoAddHttpExtractor(NettyContext c, String name, ChannelHandler
handler){
if (handler instanceof ByteToMessageDecoder
|| handler instanceof ByteToMessageCodec
|| handler instanceof CombinedChannelDuplexHandler) {
String extractorName = name+"$extractor";
if(c.channel().pipeline().context(extractorName) != null){
return;
}
c.channel().pipeline().addBefore(name, extractorName, HTTP_EXTRACTOR);
if(NettyContext.isPersistent(c.channel())){
c.onClose(() -> c.removeHandler(extractorName));
}
}
}
示例4: newSslInitiator
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
ChannelHandler newSslInitiator() {
return new ByteToMessageDecoder() {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if(in.readableBytes() < 1) {
return;
}
if('S' != in.readByte()) {
ctx.fireExceptionCaught(new IllegalStateException("SSL required but not supported by backend server"));
return;
}
ctx.pipeline().remove(this);
ctx.pipeline().addFirst(
SslContextBuilder
.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.build()
.newHandler(ctx.alloc()));
}
};
}
示例5: createFrameDecoder
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
/**
* Creates a LengthFieldBasedFrameDecoder where the first 8 bytes are the length of the frame.
* This is used before all decoders.
*/
public static ByteToMessageDecoder createFrameDecoder() {
// maxFrameLength = 2G
// lengthFieldOffset = 0
// lengthFieldLength = 8
// lengthAdjustment = -8, i.e. exclude the 8 byte length itself
// initialBytesToStrip = 8, i.e. strip out the length field itself
return new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 8, -8, 8);
}
示例6: initChannel
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast("openChannels", transport.serverOpenChannels);
final HttpRequestDecoder decoder = new HttpRequestDecoder(
Math.toIntExact(transport.maxInitialLineLength.getBytes()),
Math.toIntExact(transport.maxHeaderSize.getBytes()),
Math.toIntExact(transport.maxChunkSize.getBytes()));
decoder.setCumulator(ByteToMessageDecoder.COMPOSITE_CUMULATOR);
ch.pipeline().addLast("decoder", decoder);
ch.pipeline().addLast("decoder_compress", new HttpContentDecompressor());
ch.pipeline().addLast("encoder", new HttpResponseEncoder());
final HttpObjectAggregator aggregator = new HttpObjectAggregator(Math.toIntExact(transport.maxContentLength.getBytes()));
if (transport.maxCompositeBufferComponents != -1) {
aggregator.setMaxCumulationBufferComponents(transport.maxCompositeBufferComponents);
}
ch.pipeline().addLast("aggregator", aggregator);
if (transport.compression) {
ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(transport.compressionLevel));
}
if (SETTING_CORS_ENABLED.get(transport.settings())) {
ch.pipeline().addLast("cors", new Netty4CorsHandler(transport.getCorsConfig()));
}
if (transport.pipelining) {
ch.pipeline().addLast("pipelining", new HttpPipeliningHandler(transport.pipeliningMaxEvents));
}
ch.pipeline().addLast("handler", requestHandler);
}
示例7: callDecode
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
/**
* Call the decode method on a netty ByteToMessageDecoder
*
* @param decoder The decoder
* @param ctx The current context
* @param input The packet to decode
* @return A list of the decoders output
* @throws InvocationTargetException If an exception happens while executing
*/
public static List<Object> callDecode(ByteToMessageDecoder decoder, ChannelHandlerContext ctx, Object input) throws InvocationTargetException {
List<Object> output = new ArrayList<>();
try {
PipelineUtil.DECODE_METHOD.invoke(decoder, ctx, input, output);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return output;
}
示例8: getDecoder
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
public ByteToMessageDecoder getDecoder() {
ByteDecoder decoder = new ByteDecoder();
decoder.setMessageCodec(msgCodec);
decoder.setHeadCodec(headCodec);
return decoder;
}
示例9: initChannel
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
protected void initChannel(final Channel channel) throws Exception
{
super.initChannel(channel);
channel.pipeline().addFirst("sslDetectionHandler", new ByteToMessageDecoder()
{
@Override
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception
{
if (byteBuf.readableBytes() < 5)
{
// To detect if SSL must be used we need to have at least 5 bytes, so return here and try again
// once more bytes a ready.
return;
}
if (SslHandler.isEncrypted(byteBuf))
{
// Connection uses SSL/TLS, replace the detection handler with a SslHandler and so use
// encryption.
SslHandler sslHandler = createSslHandler();
channelHandlerContext.pipeline().replace(this, "ssl", sslHandler);
}
else
{
// Connection use no TLS/SSL encryption, just remove the detection handler and continue without
// SslHandler in the pipeline.
channelHandlerContext.pipeline().remove(this);
}
}
});
}
示例10: initChannel
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
// Initialize our session Object when the channel is initialized, attach
// it to the channel.
ch.attr(NetworkConstants.SESSION_KEY).setIfAbsent(new PlayerIO(ch));
// Initialize the pipeline channel handlers.
ChannelDuplexHandler timeout = new IdleStateHandler(NetworkConstants.INPUT_TIMEOUT, 0, 0);
ByteToMessageDecoder loginHandshakeHandler = new LoginHandshakeHandler();
ch.pipeline().addLast("login-handshake", loginHandshakeHandler);
ch.pipeline().addLast("channel-handler", channelHandler);
ch.pipeline().addLast("timeout", timeout);
}
示例11: newDecodeHandler
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
@Override
public BukkitDecodeHandler newDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
return new BukkitDecodeHandler(info, minecraftDecoder);
}
示例12: BukkitDecodeHandler
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
public BukkitDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
this.info = info;
this.minecraftDecoder = minecraftDecoder;
}
示例13: SpongeDecodeHandler
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
public SpongeDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder) {
this.info = info;
this.minecraftDecoder = minecraftDecoder;
}
示例14: getDecoder
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
/**
* 获取解码器 @see ByteToMessageDecoder
*
* @return 解码器
*/
ByteToMessageDecoder getDecoder();
示例15: newDecodeHandler
import io.netty.handler.codec.ByteToMessageDecoder; //导入依赖的package包/类
public ByteToMessageDecoder newDecodeHandler(UserConnection info, ByteToMessageDecoder minecraftDecoder);