当前位置: 首页>>代码示例>>Java>>正文


Java ZlibCodecFactory类代码示例

本文整理汇总了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());
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:20,代码来源:FactorialClientInitializer.java

示例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());
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:22,代码来源:FactorialServerInitializer.java

示例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;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:20,代码来源:HttpContentDecompressor.java

示例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);
}
 
开发者ID:allan-huang,项目名称:remote-procedure-call,代码行数:26,代码来源:ClientChannelInitializer.java

示例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);
}
 
开发者ID:allan-huang,项目名称:remote-procedure-call,代码行数:21,代码来源:ServerChannelInitializer.java

示例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());
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:18,代码来源:FactorialServerInitializer.java

示例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);
		}
	}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:13,代码来源:GZipDetector.java

示例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);
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:10,代码来源:TelnetWriter.java

示例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);
    }
}
 
开发者ID:smoketurner,项目名称:uploader,代码行数:32,代码来源:OptionalGzipHandler.java

示例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);
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:8,代码来源:PortUnificationServerHandler.java

示例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());
}
 
开发者ID:sjsucmpe275,项目名称:fluffy,代码行数:28,代码来源:CommInit.java

示例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));
}
 
开发者ID:sjsucmpe275,项目名称:fluffy,代码行数:28,代码来源:WorkChannelInitializer.java

示例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));
}
 
开发者ID:sjsucmpe275,项目名称:fluffy,代码行数:29,代码来源:CommandChannelInitializer.java

示例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());
}
 
开发者ID:sjsucmpe275,项目名称:fluffy,代码行数:28,代码来源:MonitorServiceInitializer.java

示例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());
}
 
开发者ID:sjsucmpe275,项目名称:fluffy,代码行数:29,代码来源:MonitorInit.java


注:本文中的io.netty.handler.codec.compression.ZlibCodecFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。