Fix more test failures for UnsafeBuffer

This commit is contained in:
Chris Vest 2021-03-27 13:40:25 +01:00
parent 1fe8abecfa
commit fb7279e82f
2 changed files with 11 additions and 14 deletions

View File

@ -45,6 +45,11 @@ public interface ByteCursor {
/**
* Return the last 8 bytes read by {@link #readLong()}.
* If {@link #readLong()} has not been called on this cursor before, then {@code -1} is returned.
* <p>
* The long value is in the big-endian format, such that the highest-order by of the long value, is the byte that
* would otherwise have been produced by a {@link #readByte()} / {@link #getByte()} pair.
* This means that cursors that iterate in reverse, e.g. from {@link Buffer#openReverseCursor()}, return longs in a
* "mirrored" or "reversed" big-endian format.
*
* @return The 8 bytes, in big-endian format, that was read by the most recent successful call to
* {@link #readLong()}.

View File

@ -87,7 +87,7 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
@Override
public int capacity() {
return rsize;
return Math.max(0, rsize); // Use Math.max to make capacity of closed buffer equal to zero.
}
@Override
@ -147,6 +147,9 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
@Override
public Buffer slice(int offset, int length) {
if (length < 0) {
throw new IllegalArgumentException("Length cannot be negative: " + length + '.');
}
checkGet(offset, length);
ArcDrop<UnsafeBuffer> drop = (ArcDrop<UnsafeBuffer>) unsafeGetDrop();
drop.increment();
@ -1240,6 +1243,8 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
}
void makeInaccessible() {
roff = 0;
woff = 0;
rsize = CLOSED_SIZE;
wsize = CLOSED_SIZE;
readOnly = false;
@ -1279,19 +1284,6 @@ public class UnsafeBuffer extends RcSupport<Buffer, UnsafeBuffer> implements Buf
}
}
private RuntimeException checkWriteState(IndexOutOfBoundsException ioobe, int offset) {
if (rsize == CLOSED_SIZE) {
return bufferIsClosed();
}
if (wsize != rsize) {
return bufferIsReadOnly();
}
IndexOutOfBoundsException exception = outOfBounds(offset);
exception.addSuppressed(ioobe);
return exception;
}
private RuntimeException readAccessCheckException(int index) {
if (rsize == CLOSED_SIZE) {
throw bufferIsClosed();