private static boolean canReadBytesAt( final BytesStore bs, final long offset, final int length) { return bs.readLimit() - offset >= length; }
private void check(@NotNull BytesStore b) { for (long i = b.start(); i < b.readLimit(); i++) { int ch = b.readByte(i); if (ch < ' ') throw new AssertionError("Char " + ch); } }
/** * Does the BytesStore end with a character? * * @param c to look for * @return true if its the last character. */ default boolean endsWith(char c) { try { return readRemaining() > 0 && readUnsignedByte(readLimit() - 1) == c; } catch (BufferUnderflowException e) { throw new AssertionError(e); } }
/** * Return the long sum of the readable bytes. * * @return signed long sum. */ @Deprecated(/* remove in 1.13 */) default long longCheckSum() { long sum = 0; long i; try { for (i = readPosition(); i < readLimit() - 7; i += 8) sum += readLong(i); if (i < readLimit()) sum += readIncompleteLong(i); } catch (BufferUnderflowException e) { throw new AssertionError(e); } return sum; }
/** * Return the bytes sum of the readable bytes. * * @return unsigned byte sum. */ default int byteCheckSum() throws IORuntimeException { return byteCheckSum(readPosition(), readLimit()); }
/** * Assume ISO-8859-1 encoding, subclasses can override this. */ @Override default char charAt(int index) throws IndexOutOfBoundsException { try { return (char) readUnsignedByte(readPosition() + index); } catch (BufferUnderflowException e) { throw new IndexOutOfBoundsException((readPosition() + index) + " >= " + readLimit()); } }
@Nullable ByteBuffer byteBuffer = writingBytes.underlyingObject(); byteBuffer.position(0); byteBuffer.limit((int) writingBytes.readLimit()); fc.write(byteBuffer); } catch (IOException e) {
@NotNull @Override public Bytes<Underlying> write8bit(@Nullable BytesStore bs) throws BufferOverflowException { if (bs == null) { writeStopBit(-1); } else { long offset = bs.readPosition(); long readRemaining = Math.min(writeRemaining(), bs.readLimit() - offset); writeStopBit(readRemaining); write(bs, offset, readRemaining); } return this; }
public MappedBytes write8bit(@Nullable BytesStore bs) throws BufferOverflowException { if (bs == null) { writeStopBit(-1); } else { long offset = bs.readPosition(); long readRemaining = Math.min(writeRemaining(), bs.readLimit() - offset); writeStopBit(readRemaining); write(bs, offset, readRemaining); } return this; } }
@org.jetbrains.annotations.NotNull @NotNull default S write8bit(@Nullable BytesStore bs) throws BufferOverflowException { if (bs == null) { writeStopBit(-1); } else { long offset = bs.readPosition(); long readRemaining = Math.min(writeRemaining(), bs.readLimit() - offset); writeStopBit(readRemaining); write(bs, offset, readRemaining); } return (S) this; }
@NotNull private net.openhft.lang.io.Bytes toLangBytes(@NotNull BytesStore b, @NotNull Bytes tmpBytes, @NotNull net.openhft.lang.io.NativeBytes lb) { if (b.isDirectMemory()) { // check(b); lb.setStartPositionAddress(b.address(b.start()), b.address(b.readLimit())); // check(lb); } else { tmpBytes.clear(); tmpBytes.write(b); lb.setStartPositionAddress(tmpBytes.address(tmpBytes.start()), tmpBytes.address(tmpBytes.readLimit())); } return lb; }