Refine search
private void inACycleFound(Bytes<?> bytes) { context.closeReadLimit(bytes.capacity()); wire().readAndSetLength(bytes.readPosition()); long end = bytes.readLimit(); context.closeReadPosition(end); Jvm.optionalSafepoint(); }
/** * 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); } }
/** * @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); } }
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));
@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; }
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);
@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; } }
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); } }
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; }
/** * 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; }
/** * 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()); }
/** * 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); }
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)); } } }
@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(); } }
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; }
@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); } }
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 {
@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); }