@Override public long size() { return capacity(); }
@Override public long size() { return capacity(); }
private void throwOverflow() throws IndexOutOfBoundsException { throw new IndexOutOfBoundsException("Buffer overflow, capacity: " + capacity() + " position: " + position()); }
private void throwOverflow() throws IndexOutOfBoundsException { throw new IndexOutOfBoundsException("Buffer overflow, capacity: " + capacity() + " position: " + position()); }
@Override public long nextSetBit(long fromIndex) { if (fromIndex < 0) throw new IndexOutOfBoundsException(); long maxBit = capacity() << 3; long fromLongIndex = fromIndex & ~63; if (fromLongIndex >= maxBit) return -1; long firstByte = fromLongIndex >>> 3; if ((fromIndex & 63) != 0) { long l = readVolatileLong(firstByte) >>> fromIndex; if (l != 0) { return fromIndex + numberOfTrailingZeros(l); } firstByte += 8; } for (long i = firstByte; i < capacity(); i += 8) { long l = readLong(i); if (l != 0) return (i << 3) + numberOfTrailingZeros(l); } return -1; }
@Override public long nextSetBit(long fromIndex) { if (fromIndex < 0) throw new IndexOutOfBoundsException(); long maxBit = capacity() << 3; long fromLongIndex = fromIndex & ~63; if (fromLongIndex >= maxBit) return -1; long firstByte = fromLongIndex >>> 3; if ((fromIndex & 63) != 0) { long l = readVolatileLong(firstByte) >>> fromIndex; if (l != 0) { return fromIndex + numberOfTrailingZeros(l); } firstByte += 8; } for (long i = firstByte; i < capacity(); i += 8) { long l = readLong(i); if (l != 0) return (i << 3) + numberOfTrailingZeros(l); } return -1; }
@NotNull @Override public String toDebugString(long limit) { StringBuilder sb = new StringBuilder(200); sb.append("[pos: ").append(position()).append(", lim: ").append(limit()).append(", cap: ") .append(capacity()).append(" ] "); toString(sb, position() - limit, position(), position() + limit); return sb.toString(); }
@NotNull @Override public String toDebugString(long limit) { StringBuilder sb = new StringBuilder(200); sb.append("[pos: ").append(position()).append(", lim: ").append(limit()).append(", cap: ") .append(capacity()).append(" ] "); toString(sb, position() - limit, position(), position() + limit); return sb.toString(); }
@Override public AbstractBytes clear() { finished = false; position(0L); limit(capacity()); return this; }
@Override public AbstractBytes clear() { finished = false; position(0L); limit(capacity()); return this; }
@Override public int length() { if (position() == 0) return (int) Math.min(limit(), Integer.MAX_VALUE); else if (position() == limit() || limit() == capacity()) return (int) Math.min(position(), Integer.MAX_VALUE); else throw new IllegalStateException(); }
@Override public int length() { if (position() == 0) return (int) Math.min(limit(), Integer.MAX_VALUE); else if (position() == limit() || limit() == capacity()) return (int) Math.min(position(), Integer.MAX_VALUE); else throw new IllegalStateException(); }
@NotNull @Override public String readLine() { StringBuilder input = acquireStringBuilder(); EOL: while (position() < capacity()) { int c = readUnsignedByteOrThrow(); switch (c) { case END_OF_BUFFER: case '\n': break EOL; case '\r': long cur = position(); if (cur < capacity() && readByte(cur) == '\n') position(cur + 1); break EOL; default: input.append((char) c); break; } } return SI.intern(input); }
@NotNull @Override public String readLine() { StringBuilder input = acquireStringBuilder(); EOL: while (position() < capacity()) { int c = readUnsignedByteOrThrow(); switch (c) { case END_OF_BUFFER: case '\n': break EOL; case '\r': long cur = position(); if (cur < capacity() && readByte(cur) == '\n') position(cur + 1); break EOL; default: input.append((char) c); break; } } return SI.intern(input); }
@Override public boolean compare(long offset, RandomDataInput input, long inputOffset, long len) { if (offset < 0 || inputOffset < 0 || len < 0) throw new IndexOutOfBoundsException(); if (offset + len < 0 || offset + len > capacity() || inputOffset + len < 0 || inputOffset + len > input.capacity()) { return false; } long i = 0L; for (; i < len - 7L; i += 8L) { if (readLong(offset + i) != input.readLong(inputOffset + i)) return false; } if (i < len - 3L) { if (readInt(offset + i) != input.readInt(inputOffset + i)) return false; i += 4L; } if (i < len - 1L) { if (readChar(offset + i) != input.readChar(inputOffset + i)) return false; i += 2L; } if (i < len) { if (readByte(offset + i) != input.readByte(inputOffset + i)) return false; } return true; }
@Override public boolean compare(long offset, RandomDataInput input, long inputOffset, long len) { if (offset < 0 || inputOffset < 0 || len < 0) throw new IndexOutOfBoundsException(); if (offset + len < 0 || offset + len > capacity() || inputOffset + len < 0 || inputOffset + len > input.capacity()) { return false; } long i = 0L; for (; i < len - 7L; i += 8L) { if (readLong(offset + i) != input.readLong(inputOffset + i)) return false; } if (i < len - 3L) { if (readInt(offset + i) != input.readInt(inputOffset + i)) return false; i += 4L; } if (i < len - 1L) { if (readChar(offset + i) != input.readChar(inputOffset + i)) return false; i += 2L; } if (i < len) { if (readByte(offset + i) != input.readByte(inputOffset + i)) return false; } return true; }