@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { zlib.free(); }
@Override public void free() { if ( ctx != 0 ) { nativeCompress.end( ctx, compress ); ctx = 0; } nativeCompress.consumed = 0; nativeCompress.finished = false; }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { zlib.init( false, 0 ); }
@Override public void process(ByteBuf in, ByteBuf out) throws DataFormatException { // Smoke tests in.memoryAddress(); out.memoryAddress(); Preconditions.checkState( ctx != 0, "Invalid pointer to compress!" ); while ( !nativeCompress.finished && ( compress || in.isReadable() ) ) { out.ensureWritable( 8192 ); int processed = nativeCompress.process( ctx, in.memoryAddress() + in.readerIndex(), in.readableBytes(), out.memoryAddress() + out.writerIndex(), out.writableBytes(), compress ); in.readerIndex( in.readerIndex() + nativeCompress.consumed ); out.writerIndex( out.writerIndex() + processed ); } nativeCompress.reset( ctx, compress ); nativeCompress.consumed = 0; nativeCompress.finished = false; } }
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { int origSize = msg.readableBytes(); if ( origSize < threshold ) { DefinedPacket.writeVarInt( 0, out ); out.writeBytes( msg ); } else { DefinedPacket.writeVarInt( origSize, out ); zlib.process( msg, out ); } } }
@Override public void init(boolean compress, int level) { this.compress = compress; free(); if ( compress ) { deflater = new Deflater( level ); } else { inflater = new Inflater(); } }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { zlib.init( true, Deflater.DEFAULT_COMPRESSION ); }
@Override public void free() { if ( ctx != 0 ) { nativeCompress.end( ctx, compress ); ctx = 0; } nativeCompress.consumed = 0; nativeCompress.finished = false; }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { int size = DefinedPacket.readVarInt( in ); if ( size == 0 ) { out.add( in.slice().retain() ); in.skipBytes( in.readableBytes() ); } else { ByteBuf decompressed = ctx.alloc().directBuffer(); try { zlib.process( in, decompressed ); Preconditions.checkState( decompressed.readableBytes() == size, "Decompressed packet size mismatch" ); out.add( decompressed ); decompressed = null; } finally { if ( decompressed != null ) { decompressed.release(); } } } } }
@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { zlib.free(); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { zlib.init( true, Deflater.DEFAULT_COMPRESSION ); }
@Override public void free() { if ( ctx != 0 ) { nativeCompress.end( ctx, compress ); ctx = 0; } nativeCompress.consumed = 0; nativeCompress.finished = false; }
@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { zlib.free(); }
@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { zlib.init( false, 0 ); }
@Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { zlib.free(); }
@Override protected net.md_5.bungee.jni.zlib.BungeeZlib initialValue() { BungeeZlib zlib = NativeCodeFactory.zlib.newInstance(); zlib.init(false, Deflater.DEFAULT_COMPRESSION); return zlib; } };
@Override protected net.md_5.bungee.jni.zlib.BungeeZlib initialValue() { BungeeZlib zlib = NativeCodeFactory.zlib.newInstance(); zlib.init(true, Deflater.DEFAULT_COMPRESSION); return zlib; } };