public class Lz4FrameEncoder extends MessageToByteEncoder<ByteBuf>
ByteBuf 。
请参阅原始LZ4 Github project和LZ4 block format以获取完整说明。
由于原始的LZ4块格式不包含压缩块的大小和原始数据的大小,所以该编码器使用由Adrien Grand编写并由Yann Collet(原始LZ4库的作者)批准的格式LZ4 Java库。
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Magic * Token * Compressed * Decompressed * Checksum * * * LZ4压缩* * * *长度*长度* * *块* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ChannelHandler.Sharable| Constructor and Description |
|---|
Lz4FrameEncoder()
根据Yann Collet的作品
Github ,创建最快的LZ4编码器,其默认块大小(64 KB)和Java的xxhash哈希。
|
Lz4FrameEncoder(boolean highCompressor)
根据Yann Collet的工作
成果Github ,创建了一个新的LZ4编码器,它具有高或高压缩,默认块大小(64 KB)和Java的xxhash哈希。
|
Lz4FrameEncoder(LZ4Factory factory, boolean highCompressor, int blockSize, java.util.zip.Checksum checksum)
创建一个新的可定制的LZ4编码器。
|
Lz4FrameEncoder(LZ4Factory factory, boolean highCompressor, int blockSize, java.util.zip.Checksum checksum, int maxEncodeSize)
创建一个新的可定制的LZ4编码器。
|
| Modifier and Type | Method and Description |
|---|---|
protected ByteBuf |
allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect)
分配一个 ByteBuf ,它将用作#encode(ChannelHandlerContext, I, ByteBuf)参数。
|
ChannelFuture |
close()
关闭此 Lz4FrameEncoder并完成编码。
|
void |
close(ChannelHandlerContext ctx, ChannelPromise promise)
|
ChannelFuture |
close(ChannelPromise promise)
关闭此 Lz4FrameEncoder并完成编码。
|
protected void |
encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out)
将消息编码成 ByteBuf 。
|
void |
flush(ChannelHandlerContext ctx)
|
void |
handlerAdded(ChannelHandlerContext ctx)
子类可以忽略这个方法。
|
void |
handlerRemoved(ChannelHandlerContext ctx)
子类可以忽略这个方法。
|
boolean |
isClosed()
当且仅当压缩流已完成时才返回
true 。
|
acceptOutboundMessage, isPreferDirect, writebind, connect, deregister, disconnect, readensureNotSharable, exceptionCaught, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitexceptionCaughtpublic Lz4FrameEncoder()
public Lz4FrameEncoder(boolean highCompressor)
highCompressor - 如果
true编解码器将使用需要更多内存且速度较慢但压缩更有效的压缩器
public Lz4FrameEncoder(LZ4Factory factory,
boolean highCompressor,
int blockSize,
java.util.zip.Checksum checksum)
factory - 用户可定制的
LZ4Factory实例,它可以是JNI绑定到原始C实现,纯Java实现或使用
Unsafe的Java实现
highCompressor - 如果
true编解码器将使用需要更多内存且速度较慢但压缩效率更高的压缩器
blockSize - 一次尝试压缩的最大字节数必须> = 64且<= 32 M
checksum - 用于检查数据完整性的
Checksum实例
public Lz4FrameEncoder(LZ4Factory factory,
boolean highCompressor,
int blockSize,
java.util.zip.Checksum checksum,
int maxEncodeSize)
factory - 用户可定制的
LZ4Factory实例,它可以是JNI绑定到原始C实现,纯Java实现或使用
Unsafe的Java实现
highCompressor - 如果
true编解码器将使用需要更多内存且速度较慢但压缩效率更高的压缩器
blockSize - 一次尝试压缩的最大字节数必须> = 64且<= 32 M
checksum - 用于检查数据完整性的
Checksum实例
maxEncodeSize - 编码(压缩)缓冲区的最大大小
protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect)
MessageToByteEncoder
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws java.lang.Exception
ByteBuf 。
这个方法将被编码器处理的每个书面信息调用。
将输入缓冲区编码为输出缓冲区中的blockSize块。
只有当我们点击blockSize时数据才会被压缩和写入;
否则,它被复制到后台buffer以等待更多数据。
encode在课堂上
MessageToByteEncoder<ByteBuf>
ctx - 这MessageToByteEncoder所属的ChannelHandlerContext
in - 要编码的消息
out - 将编写消息写入其中的ByteBuf
java.lang.Exception - 发生错误时抛出
public void flush(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelOutboundHandlerAdapter
ChannelHandlerContext.flush()转发到ChannelPipeline中的下一个ChannelOutboundHandler 。
子类可以重写此方法来更改行为。
flush在界面
ChannelOutboundHandler
flush在课堂
ChannelOutboundHandlerAdapter
ctx - 进行冲洗操作的ChannelHandlerContext
java.lang.Exception - 发生错误时抛出
public boolean isClosed()
true 。
public ChannelFuture close()
Lz4FrameEncoder并完成编码。
操作完成后,会通知返回的ChannelFuture 。
public ChannelFuture close(ChannelPromise promise)
Lz4FrameEncoder并完成编码。
一旦操作完成,给定的ChannelFuture将会收到通知,并且还将返回。
public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws java.lang.Exception
ChannelOutboundHandlerAdapter
ChannelOutboundInvoker.close(ChannelPromise)转发至ChannelPipeline中的下一个ChannelOutboundHandler 。
子类可以重写此方法来更改行为。
close ,界面
ChannelOutboundHandler
close在课堂上
ChannelOutboundHandlerAdapter
ctx - 关闭操作的ChannelHandlerContext
promise - 在操作完成后通知ChannelPromise
java.lang.Exception - 发生错误时抛出
public void handlerAdded(ChannelHandlerContext ctx)
ChannelHandlerAdapter
handlerAdded在界面
ChannelHandler
handlerAdded在课堂上
ChannelHandlerAdapter
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerRemoved在界面
ChannelHandler
handlerRemoved在课堂
ChannelHandlerAdapter
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.