Top Description Fields Constructors Methods
io.netty.handler.codec.compression

public Class JZlibEncoder

extends ZlibEncoder
Class Inheritance
Imports
com.jcraft.jzlib.Deflater, .JZlib, io.netty.buffer.ByteBuf, .Unpooled, io.netty.channel.ChannelFuture, .ChannelFutureListener, .ChannelHandlerContext, .ChannelPromise, io.netty.util.concurrent.EventExecutor, .Future, .PromiseNotifier, io.netty.util.internal.EmptyArrays, .ObjectUtil, java.util.concurrent.TimeUnit

Compresses a ByteBuf using the deflate algorithm.

Field Summary

Modifier and TypeField and Description
private volatile ChannelHandlerContext
private volatile boolean
private static final int
private final int
private final Deflater
z

Deprecated as a consequence of Deflater being deprecated.

Constructor Summary

AccessConstructor and Description
public
JZlibEncoder()

Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the default wrapper (ZlibWrapper#ZLIB).

public
JZlibEncoder(int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
)

Creates a new zlib encoder with the specified compressionLevel, default window bits (15), default memory level (8), and the default wrapper (ZlibWrapper#ZLIB).

public
JZlibEncoder(ZlibWrapper wrapper)

Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the specified wrapper.

public
JZlibEncoder(ZlibWrapper wrapper, int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
)

Creates a new zlib encoder with the specified compressionLevel, default window bits (15), default memory level (8), and the specified wrapper.

public
JZlibEncoder(ZlibWrapper wrapper, int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
,
int
The base two logarithm of the size of the history buffer. The value should be in the range 9 to 15 inclusive. Larger values result in better compression at the expense of memory usage. The default value is 15.
windowBits
,
int
How much memory should be allocated for the internal compression state. 1 uses minimum memory and 9 uses maximum memory. Larger values result in better and faster compression at the expense of memory usage. The default value is 8
memLevel
)

Creates a new zlib encoder with the specified compressionLevel, the specified windowBits, the specified memLevel, and the specified wrapper.

public
JZlibEncoder(byte[]
the preset dictionary
dictionary
)

Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the specified preset dictionary.

public
JZlibEncoder(int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
,
byte[]
the preset dictionary
dictionary
)

Creates a new zlib encoder with the specified compressionLevel, default window bits (15), default memory level (8), and the specified preset dictionary.

public
JZlibEncoder(int
1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.
compressionLevel
,
int
The base two logarithm of the size of the history buffer. The value should be in the range 9 to 15 inclusive. Larger values result in better compression at the expense of memory usage. The default value is 15.
windowBits
,
int
How much memory should be allocated for the internal compression state. 1 uses minimum memory and 9 uses maximum memory. Larger values result in better and faster compression at the expense of memory usage. The default value is 8
memLevel
,
byte[]
the preset dictionary
dictionary
)

Creates a new zlib encoder with the specified compressionLevel, the specified windowBits, the specified memLevel, and the specified preset dictionary.

Method Summary

Modifier and TypeMethod and Description
public ChannelFuture
close()

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.close.

Close this ZlibEncoder and so finish the encoding.
public ChannelFuture
close(final ChannelPromise promise)

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.close.

Close this ZlibEncoder and so finish the encoding.
public void
close(final ChannelHandlerContext
the ChannelHandlerContext for which the close operation is made
ctx
,
final ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.close.

Implements io.netty.channel.ChannelOutboundHandler.close.

Calls ChannelHandlerContext#close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
private ChannelHandlerContext
ctx()

protected void
encode(ChannelHandlerContext ctx, ByteBuf
the message to encode
in
,
ByteBuf
the ByteBuf into which the encoded message will be written
out
)

Implements abstract io.netty.handler.codec.MessageToByteEncoder.encode.

Encode a message into a ByteBuf.
private ChannelFuture
public void
handlerAdded(ChannelHandlerContext ctx)

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
public boolean
isClosed()

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.isClosed.

Returns true if and only if the end of the compressed stream has been reached.

Field Detail

ctxback to summary
private volatile ChannelHandlerContext ctx
finishedback to summary
private volatile boolean finished
THREAD_POOL_DELAY_SECONDSback to summary
private static final int THREAD_POOL_DELAY_SECONDS
wrapperOverheadback to summary
private final int wrapperOverhead
zback to summary
private final Deflater z

Deprecated

as a consequence of Deflater being deprecated. See corresponding docs for further information.

Constructor Detail

JZlibEncoderback to summary
public JZlibEncoder()

Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the default wrapper (ZlibWrapper#ZLIB).

Exceptions
CompressionException:
if failed to initialize zlib
JZlibEncoderback to summary
public JZlibEncoder(int compressionLevel)

Creates a new zlib encoder with the specified compressionLevel, default window bits (15), default memory level (8), and the default wrapper (ZlibWrapper#ZLIB).

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

Exceptions
CompressionException:
if failed to initialize zlib
JZlibEncoderback to summary
public JZlibEncoder(ZlibWrapper wrapper)

Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the specified wrapper.

Exceptions
CompressionException:
if failed to initialize zlib
JZlibEncoderback to summary
public JZlibEncoder(ZlibWrapper wrapper, int compressionLevel)

Creates a new zlib encoder with the specified compressionLevel, default window bits (15), default memory level (8), and the specified wrapper.

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

Exceptions
CompressionException:
if failed to initialize zlib
JZlibEncoderback to summary
public JZlibEncoder(ZlibWrapper wrapper, int compressionLevel, int windowBits, int memLevel)

Creates a new zlib encoder with the specified compressionLevel, the specified windowBits, the specified memLevel, and the specified wrapper.

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

windowBits:int

The base two logarithm of the size of the history buffer. The value should be in the range 9 to 15 inclusive. Larger values result in better compression at the expense of memory usage. The default value is 15.

memLevel:int

How much memory should be allocated for the internal compression state. 1 uses minimum memory and 9 uses maximum memory. Larger values result in better and faster compression at the expense of memory usage. The default value is 8

Exceptions
CompressionException:
if failed to initialize zlib
JZlibEncoderback to summary
public JZlibEncoder(byte[] dictionary)

Creates a new zlib encoder with the default compression level (6), default window bits (15), default memory level (8), and the specified preset dictionary. The wrapper is always ZlibWrapper#ZLIB because it is the only format that supports the preset dictionary.

Parameters
dictionary:byte[]

the preset dictionary

Exceptions
CompressionException:
if failed to initialize zlib
JZlibEncoderback to summary
public JZlibEncoder(int compressionLevel, byte[] dictionary)

Creates a new zlib encoder with the specified compressionLevel, default window bits (15), default memory level (8), and the specified preset dictionary. The wrapper is always ZlibWrapper#ZLIB because it is the only format that supports the preset dictionary.

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

dictionary:byte[]

the preset dictionary

Exceptions
CompressionException:
if failed to initialize zlib
JZlibEncoderback to summary
public JZlibEncoder(int compressionLevel, int windowBits, int memLevel, byte[] dictionary)

Creates a new zlib encoder with the specified compressionLevel, the specified windowBits, the specified memLevel, and the specified preset dictionary. The wrapper is always ZlibWrapper#ZLIB because it is the only format that supports the preset dictionary.

Parameters
compressionLevel:int

1 yields the fastest compression and 9 yields the best compression. 0 means no compression. The default compression level is 6.

windowBits:int

The base two logarithm of the size of the history buffer. The value should be in the range 9 to 15 inclusive. Larger values result in better compression at the expense of memory usage. The default value is 15.

memLevel:int

How much memory should be allocated for the internal compression state. 1 uses minimum memory and 9 uses maximum memory. Larger values result in better and faster compression at the expense of memory usage. The default value is 8

dictionary:byte[]

the preset dictionary

Exceptions
CompressionException:
if failed to initialize zlib

Method Detail

closeback to summary
public ChannelFuture close()

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.close.

Doc from io.netty.handler.codec.compression.ZlibEncoder.close.

Close this ZlibEncoder and so finish the encoding. The returned ChannelFuture will be notified once the operation completes.

Annotations
@Override
closeback to summary
public ChannelFuture close(final ChannelPromise promise)

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.close.

Doc from io.netty.handler.codec.compression.ZlibEncoder.close.

Close this ZlibEncoder and so finish the encoding. The given ChannelFuture will be notified once the operation completes and will also be returned.

Annotations
@Override
closeback to summary
public void close(final ChannelHandlerContext ctx, final ChannelPromise promise)

Overrides io.netty.channel.ChannelOutboundHandlerAdapter.close.

Implements io.netty.channel.ChannelOutboundHandler.close.

Doc from io.netty.channel.ChannelOutboundHandlerAdapter.close.

Calls ChannelHandlerContext#close(ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelHandlerContext for which the close operation is made

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.close.

the ChannelPromise to notify once the operation completes

Annotations
@Override
ctxback to summary
private ChannelHandlerContext ctx()
encodeback to summary
protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception

Implements abstract io.netty.handler.codec.MessageToByteEncoder.encode.

Doc from io.netty.handler.codec.MessageToByteEncoder.encode.

Encode a message into a ByteBuf. This method will be called for each written message that can be handled by this encoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToByteEncoder belongs to

in:ByteBuf

the message to encode

out:ByteBuf

the ByteBuf into which the encoded message will be written

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
finishEncodeback to summary
private ChannelFuture finishEncode(ChannelHandlerContext ctx, ChannelPromise promise)
handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides io.netty.channel.ChannelHandlerAdapter.handlerAdded.

Implements io.netty.channel.ChannelHandler.handlerAdded.

Doc from io.netty.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Implements abstract io.netty.handler.codec.compression.ZlibEncoder.isClosed.

Doc from io.netty.handler.codec.compression.ZlibEncoder.isClosed.

Returns true if and only if the end of the compressed stream has been reached.

Annotations
@Override