List of usage examples for io.netty.buffer ByteBuf copy
public abstract ByteBuf copy(int index, int length);
From source file:ru.jts_dev.authserver.util.Encoder.java
License:Open Source License
public ByteBuf validateChecksum(ByteBuf buf) { if (buf.readableBytes() % 4 != 0 || buf.readableBytes() <= 4) { throw new IndexOutOfBoundsException("ByteBuf size must be multiply of 4 and more, that 4"); }//from ww w. j av a2 s . c o m long checksum = 0; long check; int i; for (i = 0; i < buf.readableBytes() - 4; i += 4) { check = buf.getInt(i); checksum ^= check; } check = buf.getInt(i); if (check != checksum) { throw new InvalidParameterException("Wrong checksum"); } return buf.copy(0, buf.readableBytes() - 4); }