本文整理汇总了Java中io.netty.handler.codec.compression.ZlibCodecFactory类的典型用法代码示例。如果您正苦于以下问题:Java ZlibCodecFactory类的具体用法?Java ZlibCodecFactory怎么用?Java ZlibCodecFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZlibCodecFactory类属于io.netty.handler.codec.compression包,在下文中一共展示了ZlibCodecFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc(), FactorialClient.HOST, FactorialClient.PORT));
}
// Enable stream compression (you can remove these two if unnecessary)
pipeline.addLast(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
// Add the number codec first,
pipeline.addLast(new BigIntegerDecoder());
pipeline.addLast(new NumberEncoder());
// and then business logic.
pipeline.addLast(new FactorialClientHandler());
}
示例2: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
}
// Enable stream compression (you can remove these two if unnecessary)
pipeline.addLast(ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
// Add the number codec first,
pipeline.addLast(new BigIntegerDecoder());
pipeline.addLast(new NumberEncoder());
// and then business logic.
// Please note we create a handler for every new channel
// because it has stateful properties.
pipeline.addLast(new FactorialServerHandler());
}
示例3: newContentDecoder
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
protected EmbeddedChannel newContentDecoder(String contentEncoding) throws Exception {
if ("gzip".equalsIgnoreCase(contentEncoding) || "x-gzip".equalsIgnoreCase(contentEncoding)) {
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
if ("deflate".equalsIgnoreCase(contentEncoding) || "x-deflate".equalsIgnoreCase(contentEncoding)) {
ZlibWrapper wrapper;
if (strict) {
wrapper = ZlibWrapper.ZLIB;
} else {
wrapper = ZlibWrapper.ZLIB_OR_NONE;
}
// To be strict, 'deflate' means ZLIB, but some servers were not implemented correctly.
return new EmbeddedChannel(ZlibCodecFactory.newZlibDecoder(wrapper));
}
// 'identity' or unsupported
return null;
}
示例4: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel channel) throws Exception {
ChannelPipeline pipeline = channel.pipeline();
// use the IdleStateHandler to get notified if you haven't received or sent data for dozens of seconds.
// If this is the case, a heartbeat will be written to the remote peer, and if this fails the connection is closed.
pipeline.addLast(this.executorGroup, "idleStateHandler", new IdleStateHandler(0, 0, Constants.HEARTBEAT_PERIOD, TimeUnit.SECONDS));
pipeline.addLast(this.executorGroup, "heartbeatHandler", heartbeatHandler);
if (this.compression) {
// Enable stream compression
pipeline.addLast(this.executorGroup, "deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast(this.executorGroup, "inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
// NUL (0x00) is a message delimiter
pipeline.addLast(this.executorGroup, "framer", new DelimiterBasedFrameDecoder(8192, Delimiters.nulDelimiter()));
// string encoder / decoder are responsible for encoding / decoding an UTF-8 string
pipeline.addLast(this.executorGroup, "encoder", utf8Encoder);
pipeline.addLast(this.executorGroup, "decoder", utf8Decoder);
// client hander is responsible for as a remoting call stub
pipeline.addLast(this.executorGroup, "clientHandler", clientHandler);
}
示例5: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel channel) throws Exception {
ChannelPipeline pipeline = channel.pipeline();
if (this.compression) {
// Enable stream compression
pipeline.addLast(this.executorGroup, "deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast(this.executorGroup, "inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
// NUL (0x00) is a message delimiter
pipeline.addLast(this.executorGroup, "framer", new DelimiterBasedFrameDecoder(8192, Delimiters.nulDelimiter()));
// string encoder / decoder are responsible for encoding / decoding an UTF-8 string
pipeline.addLast(this.executorGroup, "encoder", utf8Encoder);
pipeline.addLast(this.executorGroup, "decoder", utf8Decoder);
// server hander is responsible for as a remoting call skeleton
pipeline.addLast(this.executorGroup, "serverHandler", serverHandler);
}
示例6: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Enable stream compression (you can remove these two if unnecessary)
pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
// Add the number codec first,
pipeline.addLast("decoder", new BigIntegerDecoder());
pipeline.addLast("encoder", new NumberEncoder());
// and then business logic.
// Please note we create a handler for every new channel
// because it has stateful properties.
pipeline.addLast("handler", new FactorialServerHandler());
}
示例7: enableGzip
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
private void enableGzip(final ChannelHandlerContext ctx) {
final ChannelPipeline p = ctx.pipeline();
try {
// p.addAfter("connmgr", "gzipdeflater", new JZlibEncoder(ZlibWrapper.GZIP){
// // TODO
// });
p.addAfter("gzipdetector", "gzipinflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
p.remove(this);
} catch (Exception ex) {
log.error("Failed to add gzip handlers", ex);
}
}
示例8: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
protected void initChannel(final NioSocketChannel ch) throws Exception {
final ChannelPipeline p = ch.pipeline();
if(compressionEnabled) p.addLast("gzipdeflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
p.addLast("stringEncoder", STR_ENCODER);
p.addLast("metricEncoder", METRIC_ENCODER);
p.addLast("stringDecoder", new StringDecoder(UTF8));
p.addLast("responseHandler", RESPONSE_HANDLER);
}
示例9: decode
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in,
List<Object> out) throws Exception {
// Use the first five bytes to detect gzip
if (in.readableBytes() < 5) {
return;
}
if (SslHandler.isEncrypted(in)) {
// If the channel is encrypted, close the channel as SSL must be
// disabled and only unencrypted connections are supported.
LOGGER.warn(
"Connection is encrypted when SSL is disabled, closing");
in.clear();
ctx.close();
return;
}
final ChannelPipeline p = ctx.pipeline();
final int magic1 = in.getUnsignedByte(in.readerIndex());
final int magic2 = in.getUnsignedByte(in.readerIndex() + 1);
if (isGzip(magic1, magic2)) {
LOGGER.debug(
"Channel is gzipped, replacing gzip detector with inflater");
p.replace("gzipDetector", "inflater",
ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
} else {
LOGGER.debug("Channel is not gzipped, removing gzip detector");
p.remove(this);
}
}
示例10: enableGzip
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
private void enableGzip(ChannelHandlerContext ctx) {
ChannelPipeline p = ctx.pipeline();
p.addLast("gzipdeflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
p.addLast("gzipinflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
p.addLast("unificationB", new PortUnificationServerHandler(sslCtx, detectSsl, false));
p.remove(this);
}
示例11: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Enable stream compression (you can remove these two if unnecessary)
if (compress) {
pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
/**
* length (4 bytes).
*
* Note: max message size is 64 Mb = 67108864 bytes this defines a
* framer with a max of 64 Mb message, 4 bytes are the length, and strip
* 4 bytes
*/
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(67108864, 0, 4, 0, 4));
// decoder must be first
pipeline.addLast("protobufDecoder", new ProtobufDecoder(CommandMessage.getDefaultInstance()));
pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
pipeline.addLast("protobufEncoder", new ProtobufEncoder());
// our server processor (new instance for each connection)
pipeline.addLast("handler", new CommHandler());
}
示例12: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Enable stream compression (you can remove these two if unnecessary)
if (compress) {
pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
/**
* length (4 bytes).
*
* Note: max message size is 64 Mb = 67108864 bytes this defines a
* framer with a max of 64 Mb message, 4 bytes are the length, and strip
* 4 bytes
*/
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(67108864, 0, 4, 0, 4));
// decoder must be first
pipeline.addLast("protobufDecoder", new ProtobufDecoder(WorkMessage.getDefaultInstance()));
pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
pipeline.addLast("protobufEncoder", new ProtobufEncoder());
// our server processor (new instance for each connection)
pipeline.addLast("handler", new WorkChannelHandler (state));
}
示例13: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Enable stream compression (you can remove these two if unnecessary)
if (compress) {
pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
/**
* length (4 bytes).
*
* Note: max message size is 64 Mb = 67108864 bytes this defines a
* framer with a max of 64 Mb message, 4 bytes are the length, and strip
* 4 bytes
*/
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(67108864, 0, 4, 0, 4));
// decoder must be first
pipeline.addLast("protobufDecoder", new ProtobufDecoder(CommandMessage.getDefaultInstance()));
pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
pipeline.addLast("protobufEncoder", new ProtobufEncoder());
// our server processor (new instance for each connection)
pipeline.addLast("handler", new CommandChannelHandler (conf, cmdMessageHandler));
}
示例14: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Enable stream compression (you can remove these two if unnecessary)
if (compress) {
pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
/**
* length (4 bytes).
*
* Note: max message size is 64 Mb = 67108864 bytes this defines a
* framer with a max of 64 Mb message, 4 bytes are the length, and strip
* 4 bytes
*/
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(67108864, 0, 4, 0, 4));
// decoder must be first
pipeline.addLast("protobufDecoder", new ProtobufDecoder(ClusterMonitor.getDefaultInstance()));
pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
pipeline.addLast("protobufEncoder", new ProtobufEncoder());
// our server processor (new instance for each connection)
pipeline.addLast("handler", new MonitorHandler());
}
示例15: initChannel
import io.netty.handler.codec.compression.ZlibCodecFactory; //导入依赖的package包/类
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// Enable stream compression (you can remove these two if unnecessary)
if (compress) {
pipeline.addLast("deflater", ZlibCodecFactory.newZlibEncoder(ZlibWrapper.GZIP));
pipeline.addLast("inflater", ZlibCodecFactory.newZlibDecoder(ZlibWrapper.GZIP));
}
/**
* length (4 bytes).
*
* Note: max message size is 64 Mb = 67108864 bytes this defines a
* framer with a max of 64 Mb message, 4 bytes are the length, and strip
* 4 bytes
*/
pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(67108864, 0, 4, 0, 4));
// decoder must be first
pipeline.addLast("protobufDecoder", new ProtobufDecoder(ClusterMonitor.getDefaultInstance()));
pipeline.addLast("frameEncoder", new LengthFieldPrepender(4));
pipeline.addLast("protobufEncoder", new ProtobufEncoder());
// our server processor (new instance for each connection)
pipeline.addLast("handler", new MonitorHandler());
}