io.gomint.server.jni.zlib.ZLib类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(4.5k)|赞(0)|评价(0)|浏览(106)

本文整理了Java中io.gomint.server.jni.zlib.ZLib类的一些代码示例,展示了ZLib类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZLib类的具体详情如下:
包路径:io.gomint.server.jni.zlib.ZLib
类名称:ZLib

ZLib介绍

暂无

代码示例

代码示例来源:origin: GoMint/GoMint

@Override
public void handlerAdded( ChannelHandlerContext ctx ) throws Exception {
  zlib.init( false, true, 0 );
}

代码示例来源:origin: GoMint/GoMint

@Override
protected void encode( ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out ) throws Exception {
  int origSize = msg.readableBytes();
  if ( origSize < 256 ) {
    out.writeInt( 0 );
    out.writeBytes( msg );
  } else {
    out.writeInt( origSize );
    zlib.process( msg, out );
  }
}

代码示例来源:origin: GoMint/GoMint

@Override
public void handlerRemoved( ChannelHandlerContext ctx ) throws Exception {
  zlib.free();
}

代码示例来源:origin: GoMint/ProxProx

@Override
protected void encode( ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out ) throws Exception {
  int origSize = msg.readableBytes();
  if ( origSize < 256 ) {
    out.writeInt( 0 );
    out.writeBytes( msg );
  } else {
    out.writeInt( origSize );
    zlib.process( msg, out );
  }
}

代码示例来源:origin: GoMint/ProxProx

@Override
public void handlerAdded( ChannelHandlerContext ctx ) throws Exception {
  zlib.init( false, true, 0 );
}

代码示例来源:origin: GoMint/GoMint

@Override
public void handlerRemoved( ChannelHandlerContext ctx ) throws Exception {
  zlib.free();
}

代码示例来源:origin: GoMint/GoMint

private byte[] zlibCompress(ByteBuf inBuf) {
  ZLib compressor = this.getCompressor();
  ByteBuf outBuf = newNettyBuffer();
  try {
    compressor.process(inBuf, outBuf);
  } catch (DataFormatException e) {
    LOGGER.error("Could not compress data for network", e);
    outBuf.release();
    return null;
  }
  byte[] data = new byte[outBuf.readableBytes()];
  outBuf.readBytes(data);
  outBuf.release();
  return data;
}

代码示例来源:origin: GoMint/GoMint

@Override
public void handlerAdded( ChannelHandlerContext ctx ) throws Exception {
  zlib.init( true, true, 7 );
}

代码示例来源:origin: GoMint/ProxProx

@Override
public void handlerRemoved( ChannelHandlerContext ctx ) throws Exception {
  zlib.free();
}

代码示例来源:origin: GoMint/ProxProx

private byte[] zlibCompress( ByteBuf inBuf ) {
  ZLib compressor = this.getCompressor();
  ByteBuf outBuf = newNettyBuffer();
  try {
    compressor.process( inBuf, outBuf );
  } catch ( DataFormatException e ) {
    LOGGER.error( "Could not compress data for network", e );
    outBuf.release();
    return null;
  }
  byte[] data = new byte[outBuf.readableBytes()];
  outBuf.readBytes( data );
  outBuf.release();
  return data;
}

代码示例来源:origin: GoMint/ProxProx

@Override
public void handlerAdded( ChannelHandlerContext ctx ) throws Exception {
  zlib.init( true, true, 7 );
}

代码示例来源:origin: GoMint/ProxProx

@Override
public void handlerRemoved( ChannelHandlerContext ctx ) throws Exception {
  zlib.free();
}

代码示例来源:origin: GoMint/GoMint

@Override
protected void decode( ChannelHandlerContext ctx, ByteBuf in, List<Object> out ) throws Exception {
  int size = in.readInt();
  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();
      }
    }
  }
}

代码示例来源:origin: GoMint/GoMint

private ZLib getCompressor() {
  ZLib zLib = COMPRESSOR.get();
  if (zLib != null) {
    return zLib;
  }
  zLib = ZLIB.newInstance();
  zLib.init(true, false, 7);
  COMPRESSOR.set(zLib);
  return zLib;
}

代码示例来源:origin: GoMint/ProxProx

@Override
protected void decode( ChannelHandlerContext ctx, ByteBuf in, List<Object> out ) throws Exception {
  int size = in.readInt();
  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();
      }
    }
  }
}

代码示例来源:origin: GoMint/GoMint

private ZLib getCompressor() {
  if ( COMPRESSOR.get() == null ) {
    ZLib zLib = ZLIB.newInstance();
    zLib.init( true, false, 7 );
    COMPRESSOR.set( zLib );
    return zLib;
  }
  return COMPRESSOR.get();
}

代码示例来源:origin: GoMint/GoMint

DECOMPRESSOR.process( inBuf, outBuf );
} catch ( Exception e ) {
  e.printStackTrace();

代码示例来源:origin: GoMint/ProxProx

private ZLib getCompressor() {
  ZLib zLib = COMPRESSOR.get();
  if ( zLib != null ) {
    return zLib;
  }
  zLib = ZLIB.newInstance();
  zLib.init( true, false, 7 );
  COMPRESSOR.set( zLib );
  return zLib;
}

代码示例来源:origin: GoMint/GoMint

this.decompressor.process(inBuf, outBuf);
} catch (DataFormatException e) {
  LOGGER.error("Failed to decompress batch packet", e);

代码示例来源:origin: GoMint/ProxProx

protected void initDecompressor() {
  this.decompressor = ZLIB.newInstance();
  this.decompressor.init( false, false, 7 );
}

相关文章