@Override public long get(BytesStore bytes, long index) { return bytes.readByte(index); }
default int byteCheckSum(long start, long end) { int sum = 0; for (long i = start; i < end; i++) { sum += readByte(i); } return sum & 0xFF; }
@Override public int getModificationIteratorsCount() { return (bs.readByte(offset + 29)) & 0xFF; }
@Override public boolean getModificationIteratorInitAt(int index) { if (index < 0 || index >= 128) { throw new ArrayIndexOutOfBoundsException(index + " is out of bounds, array length 128"); } int bitOffset = 240 + index; int byteOffset = bitOffset / 8; int bitShift = bitOffset & 7; return (bs.readByte(offset + byteOffset) & (1 << bitShift)) != 0; }
@Override public boolean getValue() { byte b = bytes.readByte(offset); if (b == FALSE) return false; if (b == TRUE) return true; throw new IllegalStateException("unexpected code=" + b); }
private static boolean isEqual1(@NotNull char[] chars, @NotNull BytesStore bytesStore, long readPosition) throws BufferUnderflowException { for (int i = 0; i < chars.length; i++) { int b = bytesStore.readByte(readPosition + i) & 0xFF; if (b != chars[i]) return false; } return true; }
@Override public byte readByte(long offset) throws BufferUnderflowException { readCheckOffset(offset, 1, true); return bytesStore.readByte(offset); }
@Override public byte readByte() { try { long offset = readOffsetPositionMoved(1); return bytesStore.readByte(offset); } catch (BufferUnderflowException e) { return 0; } }
@Override public int addModificationIteratorsCount(int addition) { int oldModificationIteratorsCount = (bs.readByte(offset + 29)) & 0xFF; int newModificationIteratorsCount = oldModificationIteratorsCount + addition; if (newModificationIteratorsCount < 0 || newModificationIteratorsCount > 128) { throw new IllegalStateException("(bs.readByte(offset + 29)) & 0xFF should be in [0, 128] range, the value was " + oldModificationIteratorsCount + ", + " + addition + " = " + newModificationIteratorsCount + " out of the range"); } bs.writeByte(offset + 29, (byte) (newModificationIteratorsCount)); return newModificationIteratorsCount; }
@Override public void setModificationIteratorInitAt(int index, boolean _modificationIteratorInit) { if (index < 0 || index >= 128) { throw new ArrayIndexOutOfBoundsException(index + " is out of bounds, array length 128"); } int bitOffset = 240 + index; int byteOffset = bitOffset / 8; int bitShift = bitOffset & 7; int b = bs.readByte(offset + byteOffset); if (_modificationIteratorInit) { b |= (1 << bitShift); } else { b &= ~(1 << bitShift); } bs.writeByte(offset + byteOffset, (byte) b); }
@Java9 private static boolean isEqual1(@NotNull byte[] bytes, byte coder, @NotNull BytesStore bytesStore, long readPosition) throws BufferUnderflowException { for (int i = 0; i < bytes.length; i++) { int b = bytesStore.readByte(readPosition + i) & 0xFF; char c; if (coder == 0) { c = (char) (bytes[i] & 0xFF); } else { c = (char) (((bytes[i + 1] & 0xFF) << 8) | (bytes[i] & 0xFF)); i++; } if (b != c) return false; } return true; }
/** * Perform a <i>not</i> atomic add and get operation for a byte value. * * @param offset to add and get * @param adding value to add, can be 1 * @return the sum */ @Deprecated(/* remove in 1.13 */) default byte addAndGetByteNotAtomic(long offset, byte adding) throws BufferUnderflowException { try { byte r = (byte) (readByte(offset) + adding); writeByte(offset, r); return r; } catch (BufferOverflowException e) { throw new AssertionError(e); } }
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); } }
@NotNull protected String toString0() { int length = (int) Math.min(Integer.MAX_VALUE, readRemaining()); @NotNull char[] chars = new char[length]; try { for (int i = 0; i < length; i++) { chars[i] = (char) (bytesStore.readByte(readPosition() + i) & 0xFF); } } catch (BufferUnderflowException e) { // ignored } return StringUtils.newString(chars); }
@Override public long readStopBit() throws IORuntimeException { long offset = readOffsetPositionMoved(1); byte l = bytesStore.readByte(offset); if (l >= 0) return l; return BytesInternal.readStopBit0(this, l); }
@Override public char readStopBitChar() throws IORuntimeException { long offset = readOffsetPositionMoved(1); byte l = bytesStore.readByte(offset); if (l >= 0) return (char) l; return (char) BytesInternal.readStopBit0(this, l); }
public static boolean contentEqual(@org.jetbrains.annotations.Nullable @Nullable BytesStore a, @org.jetbrains.annotations.Nullable @Nullable BytesStore b) { if (a == null) return b == null; if (b == null) return false; if (a.readRemaining() != b.readRemaining()) return false; long aPos = a.readPosition(); long bPos = b.readPosition(); long length = a.readRemaining(); long i; for (i = 0; i < length - 7; i += 8) { if (a.readLong(aPos + i) != b.readLong(bPos + i)) return false; } for (; i < length; i++) { if (a.readByte(aPos + i) != b.readByte(bPos + i)) return false; } return true; }
/** * Copy the data to another BytesStore as long as there is space available in the destination store. * * @param store to copy to * @return how many bytes were copied */ default long copyTo(@NotNull BytesStore store) { long readPos = readPosition(); long writePos = store.writePosition(); long copy = min(readRemaining(), store.capacity()); long i = 0; try { for (; i < copy - 7; i += 8) store.writeLong(writePos + i, readLong(readPos + i)); for (; i < copy; i++) store.writeByte(writePos + i, readByte(readPos + i)); } catch (BufferOverflowException | BufferUnderflowException e) { throw new AssertionError(e); } return copy; }
public boolean equalsBytes(@NotNull BytesStore b2, long remaining) { long i = 0; for (; i < (remaining - 7); i += 8) { if (readLong(readPosition() + i) != b2.readLong(b2.readPosition() + i)) { return false; } } for (; i < remaining; i++) { if (readByte(readPosition() + i) != b2.readByte(b2.readPosition() + i)) { return false; } } return true; }
@Override public void writeMarshallable(BytesOut bytes) { bytes.writeInt((bs.readInt(offset + 0)) & ((1 << 24) - 1)); bytes.writeLong((bs.readLong(offset + 3)) & ((1L << 40) - 1)); bytes.writeLong((bs.readLong(offset + 8)) & ((1L << 40) - 1)); bytes.writeLong((bs.readInt(offset + 13)) & 0xFFFFFFFFL); bytes.writeLong(bs.readLong(offset + 17)); bytes.writeInt(bs.readInt(offset + 25)); bytes.writeInt((bs.readByte(offset + 29)) & 0xFF); for (int index = 0; index < 128; index++) { bytes.writeBoolean(getModificationIteratorInitAt(index)); } }