io.netty.buffer.ByteBuf.indexOf()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(344)

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

ByteBuf.indexOf介绍

[英]Locates the first occurrence of the specified value in this buffer. The search takes place from the specified fromIndex(inclusive) to the specified toIndex (exclusive).

If fromIndex is greater than toIndex, the search is performed in a reversed order.

This method does not modify readerIndex or writerIndex of this buffer.
[中]查找此缓冲区中指定值的第一个匹配项。搜索从指定的fromIndex(包含)到指定的toIndex(独占)。
如果fromIndex大于toIndex,则按相反顺序执行搜索。
此方法不修改此缓冲区的readerIndex或writerIndex。

代码示例

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

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  return buf.indexOf(fromIndex, toIndex, value);
}

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

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  return buf.indexOf(fromIndex, toIndex, value);
}

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

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  return buf.indexOf(fromIndex, toIndex, value);
}

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

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  return buf.indexOf(fromIndex, toIndex, value);
}

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

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  if (fromIndex == toIndex) {
    return -1;
  }
  if (Math.max(fromIndex, toIndex) > buffer.writerIndex()) {
    throw REPLAY;
  }
  return buffer.indexOf(fromIndex, toIndex, value);
}

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

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  return buf.indexOf(fromIndex, toIndex, value);
}

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

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  return buf.indexOf(fromIndex, toIndex, value);
}

代码示例来源:origin: micronaut-projects/micronaut-core

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  return byteBuf.indexOf(fromIndex, toIndex, value);
}

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

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  if (fromIndex == toIndex) {
    return -1;
  }
  if (Math.max(fromIndex, toIndex) > buffer.writerIndex()) {
    throw REPLAY;
  }
  return buffer.indexOf(fromIndex, toIndex, value);
}

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

@Override
public int indexOf(int fromIndex, int toIndex, byte value) {
  if (fromIndex == toIndex) {
    return -1;
  }
  if (Math.max(fromIndex, toIndex) > buffer.writerIndex()) {
    throw REPLAY;
  }
  return buffer.indexOf(fromIndex, toIndex, value);
}

代码示例来源:origin: ainilili/ratel

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  int startIndex = -1;
  int endIndex = -1;
  if((startIndex = in.indexOf(in.readerIndex(), in.writerIndex(), TransferProtocolUtils.PROTOCOL_HAED)) != -1 && 
      (endIndex = in.indexOf(startIndex + 1, in.writerIndex(), TransferProtocolUtils.PROTOCOL_TAIL)) != -1) {
    endIndex ++;
    byte[] bytes = new byte[endIndex - startIndex];
    in.skipBytes(startIndex - in.readerIndex());
    in.readBytes(bytes, 0, bytes.length);
    out.add(bytes);
  }
}

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

private static String readString(ByteBuf buf) {
  String result = null;
  int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0);
  if (index > buf.readerIndex()) {
    result = buf.readSlice(index - buf.readerIndex()).toString(StandardCharsets.US_ASCII);
  }
  buf.readByte();
  return result;
}

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

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 'E'));
  int endIndex = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 'E');
  if (endIndex > 0) {
    return buf.readRetainedSlice(endIndex - buf.readerIndex());
  } else {
    return buf.readRetainedSlice(buf.readableBytes()); // assume full frame
  }
}

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

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')');
  if (endIndex > 0) {
    endIndex += 1 + 3;
    if (buf.writerIndex() >= endIndex) {
      return buf.readRetainedSlice(endIndex - buf.readerIndex());
    }
  }
  return null;
}

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

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  if (buf.readableBytes() < 80) {
    return null;
  }
  int spaceIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ' ');
  if (spaceIndex == -1) {
    return null;
  }
  int endIndex = buf.indexOf(spaceIndex, buf.writerIndex(), (byte) ',');
  if (endIndex == -1) {
    return null;
  }
  return buf.readRetainedSlice(endIndex + 1);
}

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

private Object decodeNew(ByteBuf buf) {
  int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '@');
  if (index < 0) {
    return null;
  }
  if (buf.writerIndex() >= index + 1) {
    ByteBuf frame = buf.readRetainedSlice(index - buf.readerIndex());
    buf.skipBytes(1); // delimiter
    return frame;
  }
  return null;
}

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

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf buf) throws Exception {
  ByteBuf result = (ByteBuf) super.decode(ctx, buf);
  if (result != null) {
    int index = result.indexOf(result.readerIndex(), result.writerIndex(), (byte) '$');
    if (index == -1) {
      return result;
    } else {
      result.skipBytes(index);
      return result.readRetainedSlice(result.readableBytes());
    }
  }
  return null;
}

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

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  int beginIndex = findHeader(buf);
  if (beginIndex >= 0) {
    buf.readerIndex(beginIndex);
    int endIndex = buf.indexOf(beginIndex, buf.writerIndex(), (byte) '\n');
    if (endIndex >= 0) {
      ByteBuf frame = buf.readRetainedSlice(endIndex - beginIndex);
      buf.readByte(); // delimiter
      return frame;
    }
  }
  return null;
}

代码示例来源:origin: normanmaurer/netty-in-action

@Override
  protected Object decode(ChannelHandlerContext ctx, ByteBuf buffer)
    throws Exception {
    ByteBuf frame = (ByteBuf) super.decode(ctx, buffer);
    if (frame == null) {
      return null;
    }
    int index = frame.indexOf(frame.readerIndex(),
        frame.writerIndex(), SPACE);
    return new Cmd(frame.slice(frame.readerIndex(), index),
        frame.slice(index + 1, frame.writerIndex()));
  }
}

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

private int findHeader(ByteBuf buffer) {
  int guessedIndex = buffer.indexOf(buffer.readerIndex(), buffer.writerIndex(), (byte) '$');
  while (guessedIndex != -1 && buffer.writerIndex() - guessedIndex >= 5) {
    if (buffer.getByte(guessedIndex + 4) == ','
          && isLetter(buffer.getByte(guessedIndex + 1))
          && isLetter(buffer.getByte(guessedIndex + 2))
          && isLetter(buffer.getByte(guessedIndex + 3))) {
      return guessedIndex;
    }
    guessedIndex = buffer.indexOf(guessedIndex, buffer.writerIndex(), (byte) '$');
  }
  return -1;
}

相关文章

ByteBuf类方法