验证一个数组(buffer)中 capacity,index,length 是否合法的方法(代码来自Netty 的byteBuf)

public static boolean isOutOfBounds(int index, int length, int capacity) {
  return (index | length | (index + length) | (capacity - (index + length))) < 0;
}

posted @ 2018-03-30 22:55  grayfox  阅读(166)  评论(0编辑  收藏  举报