Example usage for io.netty.channel ChannelPromise setSuccess

List of usage examples for io.netty.channel ChannelPromise setSuccess

Introduction

In this page you can find the example usage for io.netty.channel ChannelPromise setSuccess.

Prototype

ChannelPromise setSuccess();

Source Link

Usage

From source file:tp.MyJZLibEncoder.java

private ChannelFuture finishEncode(final ChannelHandlerContext ctx, ChannelPromise promise) {
    if (!finished.compareAndSet(false, true)) {
        promise.setSuccess();
        return promise;
    }/*from   w  ww  .j  a  v  a 2s .co  m*/

    ByteBuf footer = ctx.alloc().buffer();
    synchronized (deflater) {
        deflater.finish();
        while (!deflater.finished()) {
            int numBytes = deflater.deflate(encodeBuf, 0, encodeBuf.length);
            footer.writeBytes(encodeBuf, 0, numBytes);
        }
        if (gzip) {
            int crcValue = (int) crc.getValue();
            int uncBytes = deflater.getTotalIn();
            footer.writeByte(crcValue);
            footer.writeByte(crcValue >>> 8);
            footer.writeByte(crcValue >>> 16);
            footer.writeByte(crcValue >>> 24);
            footer.writeByte(uncBytes);
            footer.writeByte(uncBytes >>> 8);
            footer.writeByte(uncBytes >>> 16);
            footer.writeByte(uncBytes >>> 24);
        }
        deflater.end();
    }

    return ctx.writeAndFlush(footer, promise);
}