net.openhft.chronicle.bytes.Bytes.readLimit()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(114)

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

Bytes.readLimit介绍

暂无

代码示例

代码示例来源:origin: OpenHFT/Chronicle-Queue

@NotNull
private Wire readAnywhere(@NotNull Wire wire) {
  Bytes<?> bytes = wire.bytes();
  bytes.readLimit(bytes.capacity());
  return wire;
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

private void inACycleFound(Bytes<?> bytes) {
  context.closeReadLimit(bytes.capacity());
  wire().readAndSetLength(bytes.readPosition());
  long end = bytes.readLimit();
  context.closeReadPosition(end);
  Jvm.optionalSafepoint();
}

代码示例来源:origin: net.openhft/chronicle-bytes

/**
 * The buffer is not modified by this call
 *
 * @param buffer   the buffer to use
 * @param position the position to create the string from
 * @param len      the number of characters to show in the string
 * @return a string contain the text from offset {@code position}
 */
static String toString(@NotNull final Bytes buffer, long position, long len)
    throws BufferUnderflowException {
  final long pos = buffer.readPosition();
  final long limit = buffer.readLimit();
  buffer.readPositionRemaining(position, len);
  try {
    @NotNull final StringBuilder builder = new StringBuilder();
    while (buffer.readRemaining() > 0) {
      builder.append((char) buffer.readByte());
    }
    // remove the last comma
    return builder.toString();
  } finally {
    buffer.readLimit(limit);
    buffer.readPosition(pos);
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

/**
 * @return a Bytes to wrap this ByteStore from the start() to the realCapacity().
 * @throws IllegalStateException if this Bytes has been released.
 */
@Override
@NotNull
default Bytes<Underlying> bytesForRead() throws IllegalStateException {
  try {
    return bytesForWrite()
        .readLimit(writeLimit())
        .readPosition(start());
  } catch (BufferUnderflowException e) {
    throw new IllegalStateException(e);
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

void setPositionForSequenceNumber(@NotNull ExcerptContext ec,
                 long sequenceNumber,
                 long position) throws UnrecoverableTimeoutException, StreamCorruptedException {
  if (secondaryAddress > bytes.capacity())
    throw new IllegalStateException("sa2: " + secondaryAddress);
  bytes.readLimit(bytes.capacity());
  LongArrayValues indexValues = arrayForAddress(wire, secondaryAddress);
  int index3 = (int) ((sequenceNumber >>> indexSpacingBits) & (indexCount - 1));

代码示例来源:origin: net.openhft/chronicle-bytes

@org.jetbrains.annotations.NotNull
@NotNull
public static Bytes asBytes(@org.jetbrains.annotations.NotNull @NotNull RandomDataOutput bytes, long position, long limit)
    throws IllegalStateException, BufferOverflowException, BufferUnderflowException {
  Bytes sbytes = bytes.bytesForWrite();
  sbytes.writeLimit(limit);
  sbytes.readLimit(limit);
  sbytes.readPosition(position);
  return sbytes;
}

代码示例来源:origin: net.openhft/chronicle-bytes

public static String toHexString(@org.jetbrains.annotations.NotNull @NotNull final Bytes bytes, long offset, long len)
    throws BufferUnderflowException {
  if (len == 0)
  @org.jetbrains.annotations.NotNull int[] lastLine = new int[width];
  @org.jetbrains.annotations.NotNull String sep = "";
  long position = bytes.readPosition();
  long limit = bytes.readLimit();
    bytes.readLimit(limit);
    bytes.readPosition(position);

代码示例来源:origin: OpenHFT/Chronicle-Queue

@Override
public void close() {
  try {
    if (rollbackOnClose) {
      present = false;
      if (start != -1)
        wire.bytes().readPosition(start).readLimit(readLimit);
      start = -1;
      return;
    }
    if (isPresent() && !isMetaData())
      incrementIndex();
    super.close();
    // assert wire == null || wire.endUse();
  } finally {
    rollbackOnClose = false;
  }
}

代码示例来源:origin: net.openhft/chronicle-queue

@NotNull
private Wire readAnywhere(@NotNull Wire wire) {
  Bytes<?> bytes = wire.bytes();
  bytes.readLimit(bytes.capacity());
  return wire;
}

代码示例来源:origin: net.openhft/chronicle-bytes

default void readWithLength(long length, @NotNull BytesOut<Underlying> bytesOut)
    throws BufferUnderflowException, IORuntimeException {
  if (length > readRemaining())
    throw new BufferUnderflowException();
  long limit0 = readLimit();
  long limit = readPosition() + length;
  boolean lenient = lenient();
  try {
    lenient(true);
    readLimit(limit);
    bytesOut.write(this);
  } finally {
    readLimit(limit0);
    readPosition(limit);
    lenient(lenient);
  }
}

代码示例来源:origin: OpenHFT/Chronicle-Queue

private static long readMessage(Bytes<?> bytes) {
  Jvm.safepoint();
  long start = bytes.readLong();
  if (true) {
    long rp = bytes.readPosition();
    long rl = bytes.readLimit();
    long addr = bytes.addressForRead(rp);
    long addrEnd = bytes.addressForRead(rl);
    Memory memory = OS.memory();
    for (addr += 8; addr + 7 < addrEnd; addr += 8)
      memory.readLong(addr);
  } else {
    while (bytes.readRemaining() > 7)
      bytes.readLong();
  }
  Jvm.safepoint();
  return start;
}

代码示例来源:origin: net.openhft/chronicle-bytes

/**
 * display the hex data of {@link Bytes} from the position() to the limit()
 *
 * @param maxLength limit the number of bytes to be dumped.
 * @return hex representation of the buffer, from example [0D ,OA, FF]
 */
@NotNull
default String toHexString(long offset, long maxLength) {
  if (Jvm.isDebug() && Jvm.stackTraceEndsWith("Bytes", 2))
    return "Not Available";
  long maxLength2 = Math.min(maxLength, readLimit() - offset);
  @NotNull String ret = BytesInternal.toHexString(this, offset, maxLength2);
  return maxLength2 < readLimit() - offset ? ret + "... truncated" : ret;
}

代码示例来源:origin: net.openhft/chronicle-bytes

/**
 * Creates a slice of the current Bytes based on its position() and limit().  As a sub-section
 * of a Bytes it cannot be elastic.
 *
 * @return a slice of the existing Bytes where the start is moved to the position and the
 * current limit determines the capacity.
 * @throws IllegalStateException if the underlying BytesStore has been released
 */
@NotNull
@Override
default Bytes<Underlying> bytesForRead() throws IllegalStateException {
  return isClear() ? BytesStore.super.bytesForRead() : new SubBytes<>(this, readPosition(), readLimit() + start());
}

代码示例来源:origin: net.openhft/saxophone

/**
 * scan a string for interesting characters that might need further
 * review.  return the number of chars that are uninteresting and can
 * be skipped.
 * (lth) hi world, any thoughts on how to make this routine faster?
 */
private void stringScan(Bytes bytes) {
  int mask = IJC | NFP | (validateUTF8 ? NUC : 0);
  long pos = bytes.readPosition();
  long limit = bytes.readLimit();
  while (pos < limit && ((CHAR_LOOKUP_TABLE[bytes.readUnsignedByte(pos)] & mask) == 0)) {
    pos++;
  }
  bytes.readPosition(pos);
}

代码示例来源:origin: net.openhft/chronicle-engine

private void logToBuffer(@NotNull WireIn in, @NotNull StringBuilder logBuffer, long start) {
  if (YamlLogging.showServerReads()) {
    logBuffer.setLength(0);
    try {
      logBuffer.append("\nServer Receives:\n")
          .append(Wires.fromSizePrefixedBlobs(in.bytes(), start));
    } catch (Exception e) {
      logBuffer.append("\n\n").append(Bytes.toString(in.bytes(), start, in.bytes().readLimit() - start));
    }
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

@org.jetbrains.annotations.NotNull
public static String toString(@org.jetbrains.annotations.NotNull @NotNull RandomDataInput bytes)
    throws IllegalStateException {
  // the output will be no larger than this
  final int size = MAX_STRING_LEN;
  @org.jetbrains.annotations.NotNull final StringBuilder sb = new StringBuilder(size);
  if (bytes.readRemaining() > size) {
    final Bytes bytes1 = bytes.bytesForRead();
    try {
      bytes1.readLimit(bytes1.readPosition() + size);
      toString(bytes1, sb);
      return sb.toString() + "...";
    } finally {
      bytes1.release();
    }
  } else {
    toString(bytes, sb);
    return sb.toString();
  }
}

代码示例来源:origin: net.openhft/saxophone

boolean on() throws IOException {
  Bytes buf = lexer.outBuf;
  long bufPos = lexer.outPos;
  long bufLen = lexer.outLen;
  boolean borrowBuf = buf.readPosition() != bufPos ||
      buf.readRemaining() != bufLen;
  long pos = 0, lim = 0;
  if (borrowBuf) {
    pos = buf.readPosition();
    lim = buf.readLimit();
    //buf.clear();
    buf.readLimit(bufPos + bufLen);
    buf.readPosition(bufPos);
  }
  boolean go = apply(value(buf));
  if (borrowBuf) {
    //buf.clear();
    buf.readLimit(lim);
    buf.readPosition(pos);
  }
  return go;
}

代码示例来源:origin: net.openhft/chronicle-bytes

@Override
  protected void setValue(Object o, @NotNull BytesIn read) throws IllegalAccessException, IORuntimeException {
    @NotNull Bytes bytes = (Bytes) field.get(o);
    long stopBit = read.readStopBit();
    if (stopBit == -1) {
      if (bytes != null)
        bytes.release();
      field.set(o, null);
      return;
    }
    int length = Maths.toUInt31(stopBit);
    @NotNull Bytes bs;
    if (bytes == null) {
      bs = Bytes.elasticHeapByteBuffer(length);
    } else {
      bs = bytes;
    }
    Object uo = bs.underlyingObject();
    if (uo instanceof ByteBuffer && !(bs.bytesStore() instanceof NativeBytesStore)) {
      read.read(((ByteBuffer) uo).array(), 0, length);
    } else {
      bs.clear();
      read.read(bs, length);
    }
    bs.readLimit(length);
    field.set(o, bs);
  }
}

代码示例来源:origin: net.openhft/chronicle-bytes

static Bytes<ByteBuffer> wrapForRead(@NotNull ByteBuffer byteBuffer) {
  BytesStore<?, ByteBuffer> bs = BytesStore.wrap(byteBuffer);
  try {
    Bytes<ByteBuffer> bbb = bs.bytesForRead();
    bbb.readLimit(byteBuffer.limit());
    bbb.readPosition(byteBuffer.position());
    return bbb;
  } finally {

代码示例来源:origin: net.openhft/saxophone

@Override
public void parse(Bytes bytes) {
  long limit = bytes.readLimit(), limit2 = limit;
  while (limit2 > bytes.readPosition() && bytes.readByte(limit2 - 1) != FIELD_TERMINATOR)
    limit2--;
  bytes.readLimit(limit2);
  while (bytes.readRemaining() > 0) {
    long fieldNum = bytes.parseLong();
    long pos = bytes.readPosition();
    searchForTheEndOfField(bytes);
    long end = bytes.readPosition() - 1;
    bytes.readLimit(end);
    bytes.readPosition(pos);
    handler.completeMessage(bytes);
    handler.onField(fieldNum, bytes);
    bytes.readLimit(limit);
    bytes.readPosition(end + 1);
  }
  bytes.readLimit(limit);
  bytes.readPosition(limit2);
}

相关文章

微信公众号

最新文章

更多