From eef97dd1fd7a224ff6788974d47e5c142e11d56b Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Fri, 12 Feb 2021 18:22:07 +0100 Subject: [PATCH] Rename Buf to Buffer and Allocator to BufferAllocator --- .../io/netty/buffer/api/AllocatorControl.java | 8 +- .../buffer/api/{Buf.java => Buffer.java} | 43 +- ...BufAccessors.java => BufferAccessors.java} | 390 ++-- .../{Allocator.java => BufferAllocator.java} | 65 +- .../api/{BufHolder.java => BufferHolder.java} | 88 +- .../api/{BufRef.java => BufferRef.java} | 26 +- .../netty/buffer/api/CleanerPooledDrop.java | 14 +- .../netty/buffer/api/ComponentProcessor.java | 24 +- ...CompositeBuf.java => CompositeBuffer.java} | 292 +-- ...cator.java => ManagedBufferAllocator.java} | 12 +- .../io/netty/buffer/api/MemoryManager.java | 10 +- .../buffer/api/SizeClassedMemoryPool.java | 32 +- .../java/io/netty/buffer/api/Statics.java | 2 +- .../memseg/AbstractMemorySegmentManager.java | 22 +- .../buffer/api/memseg/BifurcatedDrop.java | 14 +- .../api/memseg/HeapMemorySegmentManager.java | 8 +- .../{MemSegBuf.java => MemSegBuffer.java} | 104 +- .../netty/buffer/api/memseg/package-info.java | 2 +- .../io/netty/buffer/api/package-info.java | 2 +- .../{BufRefTest.java => BufferRefTest.java} | 48 +- .../api/{BufTest.java => BufferTest.java} | 1720 +++++++++-------- .../java/io/netty/buffer/api/Fixture.java | 10 +- .../benchmarks/ByteIterationBenchmark.java | 16 +- .../benchmarks/MemSegBufAccessBenchmark.java | 22 +- ...MemorySegmentClosedByCleanerBenchmark.java | 38 +- .../buffer/api/benchmarks/SendBenchmark.java | 24 +- .../buffer/api/examples/AsyncExample.java | 12 +- .../examples/ComposingAndSlicingExample.java | 12 +- .../buffer/api/examples/FileCopyExample.java | 16 +- .../buffer/api/examples/SendExample.java | 70 +- 30 files changed, 1579 insertions(+), 1567 deletions(-) rename src/main/java/io/netty/buffer/api/{Buf.java => Buffer.java} (96%) rename src/main/java/io/netty/buffer/api/{BufAccessors.java => BufferAccessors.java} (61%) rename src/main/java/io/netty/buffer/api/{Allocator.java => BufferAllocator.java} (74%) rename src/main/java/io/netty/buffer/api/{BufHolder.java => BufferHolder.java} (58%) rename src/main/java/io/netty/buffer/api/{BufRef.java => BufferRef.java} (71%) rename src/main/java/io/netty/buffer/api/{CompositeBuf.java => CompositeBuffer.java} (86%) rename src/main/java/io/netty/buffer/api/{ManagedAllocator.java => ManagedBufferAllocator.java} (79%) rename src/main/java/io/netty/buffer/api/memseg/{MemSegBuf.java => MemSegBuffer.java} (91%) rename src/test/java/io/netty/buffer/api/{BufRefTest.java => BufferRefTest.java} (70%) rename src/test/java/io/netty/buffer/api/{BufTest.java => BufferTest.java} (79%) diff --git a/src/main/java/io/netty/buffer/api/AllocatorControl.java b/src/main/java/io/netty/buffer/api/AllocatorControl.java index 53a1bf3..35fa502 100644 --- a/src/main/java/io/netty/buffer/api/AllocatorControl.java +++ b/src/main/java/io/netty/buffer/api/AllocatorControl.java @@ -17,7 +17,7 @@ package io.netty.buffer.api; /** * Methods for accessing and controlling the internals of an allocator. - * This interface is intended to be used by implementors of the {@link Allocator}, {@link Buf} and + * This interface is intended to be used by implementors of the {@link BufferAllocator}, {@link Buffer} and * {@link MemoryManager} interfaces. */ public interface AllocatorControl { @@ -25,19 +25,19 @@ public interface AllocatorControl { * Allocate a buffer that is not tethered to any particular {@link Drop} implementation, * and return the recoverable memory object from it. *

- * This allows a buffer to implement {@link Buf#ensureWritable(int)} by having new memory allocated to it, + * This allows a buffer to implement {@link Buffer#ensureWritable(int)} by having new memory allocated to it, * without that memory being attached to some other lifetime. * * @param originator The buffer that originated the request for an untethered memory allocated. * @param size The size of the requested memory allocation, in bytes. * @return A "recoverable memory" object that is the requested allocation. */ - Object allocateUntethered(Buf originator, int size); + Object allocateUntethered(Buffer originator, int size); /** * Return memory to the allocator, after it has been untethered from it's lifetime. * This either happens if the memory has leaked and been re-captured, or if it is no longer in use by a buffer - * through {@link Buf#ensureWritable(int)}. + * through {@link Buffer#ensureWritable(int)}. * * @param memory The untethered memory to return to the allocator. */ diff --git a/src/main/java/io/netty/buffer/api/Buf.java b/src/main/java/io/netty/buffer/api/Buffer.java similarity index 96% rename from src/main/java/io/netty/buffer/api/Buf.java rename to src/main/java/io/netty/buffer/api/Buffer.java index 27524d8..4c9cb4b 100644 --- a/src/main/java/io/netty/buffer/api/Buf.java +++ b/src/main/java/io/netty/buffer/api/Buffer.java @@ -30,8 +30,9 @@ import java.nio.ByteOrder; * *

Creating a buffer

* - * Buffers are created by {@linkplain Allocator allocators}, and their {@code allocate} family of methods. - * A number of standard allocators exist, and ara available through static methods on the {@code Allocator} interface. + * Buffers are created by {@linkplain BufferAllocator allocators}, and their {@code allocate} family of methods. + * A number of standard allocators exist, and ara available through static methods on the {@code BufferAllocator} + * interface. * *

Life cycle and reference counting

* @@ -70,7 +71,7 @@ import java.nio.ByteOrder; * To send a buffer to another thread, the buffer must not have any outstanding borrows. * That is to say, all {@linkplain #acquire() acquires} must have been paired with a {@link #close()}; * all {@linkplain #slice() slices} must have been closed. - * And if this buffer is a constituent of a {@linkplain Allocator#compose(Deref...) composite buffer}, + * And if this buffer is a constituent of a {@linkplain BufferAllocator#compose(Deref...) composite buffer}, * then that composite buffer must be closed. * And if this buffer is itself a composite buffer, then it must own all of its constituent buffers. * The {@link #isOwned()} method can be used on any buffer to check if it can be sent or not. @@ -106,14 +107,14 @@ import java.nio.ByteOrder; * * */ -public interface Buf extends Rc, BufAccessors { +public interface Buffer extends Rc, BufferAccessors { /** * Change the default byte order of this buffer, and return this buffer. * * @param order The new default byte order, used by accessor methods that don't use an explicit byte order. * @return This buffer instance. */ - Buf order(ByteOrder order); + Buffer order(ByteOrder order); /** * The default byte order of this buffer. @@ -139,11 +140,11 @@ public interface Buf extends Rc, BufAccessors { * Set the reader offset. Make the next read happen from the given offset into the buffer. * * @param offset The reader offset to set. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the specified {@code offset} is less than zero or greater than the current * {@link #writerOffset()}. */ - Buf readerOffset(int offset); + Buffer readerOffset(int offset); /** * Get the current writer offset. The next write will happen at this byte offset into the byffer. @@ -156,12 +157,12 @@ public interface Buf extends Rc, BufAccessors { * Set the writer offset. Make the next write happen at the given offset. * * @param offset The writer offset to set. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the specified {@code offset} is less than the current * {@link #readerOffset()} or greater than {@link #capacity()}. * @throws IllegalStateException if this buffer is {@linkplain #readOnly() read-only}. */ - Buf writerOffset(int offset); + Buffer writerOffset(int offset); /** * Returns the number of readable bytes which is equal to {@code (writerOffset() - readerOffset())}. @@ -183,10 +184,10 @@ public interface Buf extends Rc, BufAccessors { * #writerOffset()} are not modified. * * @param value The byte value to write at every position in the buffer. - * @return This Buf. + * @return This Buffer. * @throws IllegalStateException if this buffer is {@linkplain #readOnly() read-only}. */ - Buf fill(byte value); + Buffer fill(byte value); /** * Give the native memory address backing this buffer, or return 0 if this buffer has no native memory address. @@ -199,7 +200,7 @@ public interface Buf extends Rc, BufAccessors { * * @return this buffer. */ - Buf readOnly(boolean readOnly); + Buffer readOnly(boolean readOnly); /** * Query if this buffer is read-only or not. @@ -224,7 +225,7 @@ public interface Buf extends Rc, BufAccessors { * @return A new buffer instance, with independent {@link #readerOffset()} and {@link #writerOffset()}, * that is a view of the readable region of this buffer. */ - default Buf slice() { + default Buffer slice() { return slice(readerOffset(), readableBytes()); } @@ -243,7 +244,7 @@ public interface Buf extends Rc, BufAccessors { * @return A new buffer instance, with independent {@link #readerOffset()} and {@link #writerOffset()}, * that is a view of the given region of this buffer. */ - Buf slice(int offset, int length); + Buffer slice(int offset, int length); /** * Copies the given length of data from this buffer into the given destination array, beginning at the given source @@ -303,13 +304,13 @@ public interface Buf extends Rc, BufAccessors { * @throws IndexOutOfBoundsException if the source or destination positions, or the length, are negative, * or if the resulting end positions reaches beyond the end of either this buffer or the destination array. */ - void copyInto(int srcPos, Buf dest, int destPos, int length); + void copyInto(int srcPos, Buffer dest, int destPos, int length); /** * Resets the {@linkplain #readerOffset() read offset} and the {@linkplain #writerOffset() write offset} on this * buffer to their initial values. */ - default Buf reset() { + default Buffer reset() { readerOffset(0); writerOffset(0); return this; @@ -386,8 +387,8 @@ public interface Buf extends Rc, BufAccessors { * bytes. * The buffer must be in {@linkplain #isOwned() an owned state}, or an exception will be thrown. * If this buffer already has the necessary space, then this method returns immediately. - * If this buffer does not already have the necessary space, then it will be expanded using the {@link Allocator} - * the buffer was created with. + * If this buffer does not already have the necessary space, then it will be expanded using the + * {@link BufferAllocator} the buffer was created with. * This method is the same as calling {@link #ensureWritable(int, boolean)} where {@code allowCompaction} is * {@code false}. * @@ -418,8 +419,8 @@ public interface Buf extends Rc, BufAccessors { * *
  • * Regardless of the value of the {@code allowCompaction}, the implementation may make more space available - * by just allocating more or larger buffers. This allocation would use the same {@link Allocator} that this - * buffer was created with. + * by just allocating more or larger buffers. This allocation would use the same {@link BufferAllocator} + * that this buffer was created with. *
  • *
  • * If {@code allowCompaction} is {@code true}, then the implementation may choose to do a combination of @@ -480,7 +481,7 @@ public interface Buf extends Rc, BufAccessors { * * @return A new buffer with independent and exclusive ownership over the read and readable bytes from this buffer. */ - Buf bifurcate(); + Buffer bifurcate(); /** * Discards the read bytes, and moves the buffer contents to the beginning of the buffer. diff --git a/src/main/java/io/netty/buffer/api/BufAccessors.java b/src/main/java/io/netty/buffer/api/BufferAccessors.java similarity index 61% rename from src/main/java/io/netty/buffer/api/BufAccessors.java rename to src/main/java/io/netty/buffer/api/BufferAccessors.java index d91d5b8..2ff30fe 100644 --- a/src/main/java/io/netty/buffer/api/BufAccessors.java +++ b/src/main/java/io/netty/buffer/api/BufferAccessors.java @@ -16,599 +16,599 @@ package io.netty.buffer.api; /** - * This interface is just the primitive data accessor methods that {@link Buf} exposes. + * This interface is just the primitive data accessor methods that {@link Buffer} exposes. * It can be useful if you only need the data access methods, and perhaps wish to decorate or modify their behaviour. - * Usually, you'd use the {@link Buf} interface directly, since this lets you properly control the buffer reference + * Usually, you'd use the {@link Buffer} interface directly, since this lets you properly control the buffer reference * count. */ -public interface BufAccessors { +public interface BufferAccessors { // /** - * Get the byte value at the current {@link Buf#readerOffset()}, + * Get the byte value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by {@link Byte#BYTES}. * The value is read using a two's complement 8-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The byte value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than {@link Byte#BYTES}. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than {@link Byte#BYTES}. */ byte readByte(); /** * Get the byte value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using a two's complement 8-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The byte value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Byte#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Byte#BYTES}. */ byte getByte(int roff); /** - * Get the unsigned byte value at the current {@link Buf#readerOffset()}, + * Get the unsigned byte value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by {@link Byte#BYTES}. * The value is read using an unsigned two's complement 8-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The unsigned byte value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than {@link Byte#BYTES}. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than {@link Byte#BYTES}. */ int readUnsignedByte(); /** * Get the unsigned byte value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using an unsigned two's complement 8-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The unsigned byte value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Byte#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Byte#BYTES}. */ int getUnsignedByte(int roff); /** - * Set the given byte value at the current {@link Buf#writerOffset()}, + * Set the given byte value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by {@link Byte#BYTES}. * The value is written using a two's complement 8-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The byte value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than {@link Byte#BYTES}. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than {@link Byte#BYTES}. */ - Buf writeByte(byte value); + Buffer writeByte(byte value); /** - * Set the given byte value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given byte value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using a two's complement 8-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The byte value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Byte#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Byte#BYTES}. */ - Buf setByte(int woff, byte value); + Buffer setByte(int woff, byte value); /** - * Set the given unsigned byte value at the current {@link Buf#writerOffset()}, + * Set the given unsigned byte value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by {@link Byte#BYTES}. * The value is written using an unsigned two's complement 8-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The int value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than {@link Byte#BYTES}. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than {@link Byte#BYTES}. */ - Buf writeUnsignedByte(int value); + Buffer writeUnsignedByte(int value); /** - * Set the given unsigned byte value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given unsigned byte value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using an unsigned two's complement 8-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The int value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Byte#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Byte#BYTES}. */ - Buf setUnsignedByte(int woff, int value); + Buffer setUnsignedByte(int woff, int value); /** - * Get the char value at the current {@link Buf#readerOffset()}, + * Get the char value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by 2. * The value is read using a 2-byte UTF-16 encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The char value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than 2. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than 2. */ char readChar(); /** * Get the char value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using a 2-byte UTF-16 encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The char value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus 2. + * greater than {@link Buffer#capacity()} minus 2. */ char getChar(int roff); /** - * Set the given char value at the current {@link Buf#writerOffset()}, + * Set the given char value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by 2. * The value is written using a 2-byte UTF-16 encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The char value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than 2. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than 2. */ - Buf writeChar(char value); + Buffer writeChar(char value); /** - * Set the given char value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given char value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using a 2-byte UTF-16 encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The char value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus 2. + * greater than {@link Buffer#capacity()} minus 2. */ - Buf setChar(int woff, char value); + Buffer setChar(int woff, char value); /** - * Get the short value at the current {@link Buf#readerOffset()}, + * Get the short value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by {@link Short#BYTES}. * The value is read using a two's complement 16-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The short value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than {@link Short#BYTES}. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than {@link Short#BYTES}. */ short readShort(); /** * Get the short value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using a two's complement 16-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The short value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Short#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Short#BYTES}. */ short getShort(int roff); /** - * Get the unsigned short value at the current {@link Buf#readerOffset()}, + * Get the unsigned short value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by {@link Short#BYTES}. * The value is read using an unsigned two's complement 16-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The unsigned short value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than {@link Short#BYTES}. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than {@link Short#BYTES}. */ int readUnsignedShort(); /** * Get the unsigned short value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using an unsigned two's complement 16-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The unsigned short value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Short#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Short#BYTES}. */ int getUnsignedShort(int roff); /** - * Set the given short value at the current {@link Buf#writerOffset()}, + * Set the given short value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by {@link Short#BYTES}. * The value is written using a two's complement 16-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The short value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than {@link Short#BYTES}. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than {@link Short#BYTES}. */ - Buf writeShort(short value); + Buffer writeShort(short value); /** - * Set the given short value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given short value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using a two's complement 16-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The short value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Short#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Short#BYTES}. */ - Buf setShort(int woff, short value); + Buffer setShort(int woff, short value); /** - * Set the given unsigned short value at the current {@link Buf#writerOffset()}, + * Set the given unsigned short value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by {@link Short#BYTES}. * The value is written using an unsigned two's complement 16-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The int value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than {@link Short#BYTES}. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than {@link Short#BYTES}. */ - Buf writeUnsignedShort(int value); + Buffer writeUnsignedShort(int value); /** - * Set the given unsigned short value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given unsigned short value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using an unsigned two's complement 16-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The int value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Short#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Short#BYTES}. */ - Buf setUnsignedShort(int woff, int value); + Buffer setUnsignedShort(int woff, int value); /** - * Get the int value at the current {@link Buf#readerOffset()}, + * Get the int value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by 3. * The value is read using a two's complement 24-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The int value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than 3. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than 3. */ int readMedium(); /** * Get the int value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using a two's complement 24-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The int value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus 3. + * greater than {@link Buffer#capacity()} minus 3. */ int getMedium(int roff); /** - * Get the unsigned int value at the current {@link Buf#readerOffset()}, + * Get the unsigned int value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by 3. * The value is read using an unsigned two's complement 24-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The unsigned int value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than 3. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than 3. */ int readUnsignedMedium(); /** * Get the unsigned int value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using an unsigned two's complement 24-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The unsigned int value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus 3. + * greater than {@link Buffer#capacity()} minus 3. */ int getUnsignedMedium(int roff); /** - * Set the given int value at the current {@link Buf#writerOffset()}, + * Set the given int value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by 3. * The value is written using a two's complement 24-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The int value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than 3. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than 3. */ - Buf writeMedium(int value); + Buffer writeMedium(int value); /** - * Set the given int value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given int value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using a two's complement 24-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The int value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus 3. + * greater than {@link Buffer#capacity()} minus 3. */ - Buf setMedium(int woff, int value); + Buffer setMedium(int woff, int value); /** - * Set the given unsigned int value at the current {@link Buf#writerOffset()}, + * Set the given unsigned int value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by 3. * The value is written using an unsigned two's complement 24-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The int value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than 3. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than 3. */ - Buf writeUnsignedMedium(int value); + Buffer writeUnsignedMedium(int value); /** - * Set the given unsigned int value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given unsigned int value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using an unsigned two's complement 24-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The int value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus 3. + * greater than {@link Buffer#capacity()} minus 3. */ - Buf setUnsignedMedium(int woff, int value); + Buffer setUnsignedMedium(int woff, int value); /** - * Get the int value at the current {@link Buf#readerOffset()}, + * Get the int value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by {@link Integer#BYTES}. * The value is read using a two's complement 32-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The int value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than {@link Integer#BYTES}. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than {@link Integer#BYTES}. */ int readInt(); /** * Get the int value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using a two's complement 32-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The int value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Integer#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Integer#BYTES}. */ int getInt(int roff); /** - * Get the unsigned int value at the current {@link Buf#readerOffset()}, + * Get the unsigned int value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by {@link Integer#BYTES}. * The value is read using an unsigned two's complement 32-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The unsigned int value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than {@link Integer#BYTES}. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than {@link Integer#BYTES}. */ long readUnsignedInt(); /** * Get the unsigned int value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using an unsigned two's complement 32-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The unsigned int value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Integer#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Integer#BYTES}. */ long getUnsignedInt(int roff); /** - * Set the given int value at the current {@link Buf#writerOffset()}, + * Set the given int value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by {@link Integer#BYTES}. * The value is written using a two's complement 32-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The int value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than {@link Integer#BYTES}. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than {@link Integer#BYTES}. */ - Buf writeInt(int value); + Buffer writeInt(int value); /** - * Set the given int value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given int value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using a two's complement 32-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The int value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Integer#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Integer#BYTES}. */ - Buf setInt(int woff, int value); + Buffer setInt(int woff, int value); /** - * Set the given unsigned int value at the current {@link Buf#writerOffset()}, + * Set the given unsigned int value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by {@link Integer#BYTES}. * The value is written using an unsigned two's complement 32-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The long value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than {@link Integer#BYTES}. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than {@link Integer#BYTES}. */ - Buf writeUnsignedInt(long value); + Buffer writeUnsignedInt(long value); /** - * Set the given unsigned int value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given unsigned int value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using an unsigned two's complement 32-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The long value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Integer#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Integer#BYTES}. */ - Buf setUnsignedInt(int woff, long value); + Buffer setUnsignedInt(int woff, long value); /** - * Get the float value at the current {@link Buf#readerOffset()}, + * Get the float value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by {@link Float#BYTES}. * The value is read using a 32-bit IEEE floating point encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The float value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than {@link Float#BYTES}. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than {@link Float#BYTES}. */ float readFloat(); /** * Get the float value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using a 32-bit IEEE floating point encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The float value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Float#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Float#BYTES}. */ float getFloat(int roff); /** - * Set the given float value at the current {@link Buf#writerOffset()}, + * Set the given float value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by {@link Float#BYTES}. * The value is written using a 32-bit IEEE floating point encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The float value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than {@link Float#BYTES}. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than {@link Float#BYTES}. */ - Buf writeFloat(float value); + Buffer writeFloat(float value); /** - * Set the given float value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given float value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using a 32-bit IEEE floating point encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The float value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Float#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Float#BYTES}. */ - Buf setFloat(int woff, float value); + Buffer setFloat(int woff, float value); /** - * Get the long value at the current {@link Buf#readerOffset()}, + * Get the long value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by {@link Long#BYTES}. * The value is read using a two's complement 64-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The long value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than {@link Long#BYTES}. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than {@link Long#BYTES}. */ long readLong(); /** * Get the long value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using a two's complement 64-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The long value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Long#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Long#BYTES}. */ long getLong(int roff); /** - * Set the given long value at the current {@link Buf#writerOffset()}, + * Set the given long value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by {@link Long#BYTES}. * The value is written using a two's complement 64-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The long value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than {@link Long#BYTES}. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than {@link Long#BYTES}. */ - Buf writeLong(long value); + Buffer writeLong(long value); /** - * Set the given long value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given long value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using a two's complement 64-bit encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The long value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Long#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Long#BYTES}. */ - Buf setLong(int woff, long value); + Buffer setLong(int woff, long value); /** - * Get the double value at the current {@link Buf#readerOffset()}, + * Get the double value at the current {@link Buffer#readerOffset()}, * and increases the reader offset by {@link Double#BYTES}. * The value is read using a 64-bit IEEE floating point encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @return The double value at the current reader offset. - * @throws IndexOutOfBoundsException If {@link Buf#readableBytes} is less than {@link Double#BYTES}. + * @throws IndexOutOfBoundsException If {@link Buffer#readableBytes} is less than {@link Double#BYTES}. */ double readDouble(); /** * Get the double value at the given reader offset. - * The {@link Buf#readerOffset()} is not modified. + * The {@link Buffer#readerOffset()} is not modified. * The value is read using a 64-bit IEEE floating point encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param roff The read offset, an absolute offset into this buffer, to read from. * @return The double value at the given offset. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Double#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Double#BYTES}. */ double getDouble(int roff); /** - * Set the given double value at the current {@link Buf#writerOffset()}, + * Set the given double value at the current {@link Buffer#writerOffset()}, * and increase the writer offset by {@link Double#BYTES}. * The value is written using a 64-bit IEEE floating point encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param value The double value to write. - * @return This Buf. - * @throws IndexOutOfBoundsException If {@link Buf#writableBytes} is less than {@link Double#BYTES}. + * @return This Buffer. + * @throws IndexOutOfBoundsException If {@link Buffer#writableBytes} is less than {@link Double#BYTES}. */ - Buf writeDouble(double value); + Buffer writeDouble(double value); /** - * Set the given double value at the given write offset. The {@link Buf#writerOffset()} is not modified. + * Set the given double value at the given write offset. The {@link Buffer#writerOffset()} is not modified. * The value is written using a 64-bit IEEE floating point encoding, - * with the {@link Buf#order() configured} default byte order. + * with the {@link Buffer#order() configured} default byte order. * * @param woff The write offset, an absolute offset into this buffer to write to. * @param value The double value to write. - * @return This Buf. + * @return This Buffer. * @throws IndexOutOfBoundsException if the given offset is out of bounds of the buffer, that is, less than 0 or - * greater than {@link Buf#capacity()} minus {@link Double#BYTES}. + * greater than {@link Buffer#capacity()} minus {@link Double#BYTES}. */ - Buf setDouble(int woff, double value); + Buffer setDouble(int woff, double value); // } diff --git a/src/main/java/io/netty/buffer/api/Allocator.java b/src/main/java/io/netty/buffer/api/BufferAllocator.java similarity index 74% rename from src/main/java/io/netty/buffer/api/Allocator.java rename to src/main/java/io/netty/buffer/api/BufferAllocator.java index 726027e..76c89d8 100644 --- a/src/main/java/io/netty/buffer/api/Allocator.java +++ b/src/main/java/io/netty/buffer/api/BufferAllocator.java @@ -18,9 +18,9 @@ package io.netty.buffer.api; import java.nio.ByteOrder; /** - * Interface for {@link Buf} allocators. + * Interface for {@link Buffer} allocators. */ -public interface Allocator extends AutoCloseable { +public interface BufferAllocator extends AutoCloseable { static void checkSize(long size) { if (size < 1) { throw new IllegalArgumentException("Buffer size must be positive, but was " + size + '.'); @@ -34,28 +34,28 @@ public interface Allocator extends AutoCloseable { } /** - * Allocate a {@link Buf} of the given size in bytes. This method may throw an {@link OutOfMemoryError} if there is - * not enough free memory available to allocate a {@link Buf} of the requested size. + * Allocate a {@link Buffer} of the given size in bytes. This method may throw an {@link OutOfMemoryError} if there + * is not enough free memory available to allocate a {@link Buffer} of the requested size. *

    * The buffer will use the current platform native byte order by default, for accessor methods that don't have an * explicit byte order. * - * @param size The size of {@link Buf} to allocate. - * @return The newly allocated {@link Buf}. + * @param size The size of {@link Buffer} to allocate. + * @return The newly allocated {@link Buffer}. */ - Buf allocate(int size); + Buffer allocate(int size); /** - * Allocate a {@link Buf} of the given size in bytes. This method may throw an {@link OutOfMemoryError} if there is - * not enough free memory available to allocate a {@link Buf} of the requested size. + * Allocate a {@link Buffer} of the given size in bytes. This method may throw an {@link OutOfMemoryError} if there + * is not enough free memory available to allocate a {@link Buffer} of the requested size. *

    * The buffer will use the given byte order by default. * - * @param size The size of {@link Buf} to allocate. + * @param size The size of {@link Buffer} to allocate. * @param order The default byte order used by the accessor methods that don't have an explicit byte order. - * @return The newly allocated {@link Buf}. + * @return The newly allocated {@link Buffer}. */ - default Buf allocate(int size, ByteOrder order) { + default Buffer allocate(int size, ByteOrder order) { return allocate(size).order(order); } @@ -68,18 +68,18 @@ public interface Allocator extends AutoCloseable { * If the buffers are allocated for the purpose of participating in the composite buffer, * then they should be closed as soon as the composite buffer has been created, like in this example: *

    {@code
    -     *     try (Buf a = allocator.allocate(size);
    -     *          Buf b = allocator.allocate(size)) {
    +     *     try (Buffer a = allocator.allocate(size);
    +     *          Buffer b = allocator.allocate(size)) {
          *         return allocator.compose(a, b); // Reference counts for 'a' and 'b' incremented here.
          *     } // Reference count for 'a' and 'b' decremented here; composite buffer now holds the last references.
          * }
    *

    - * {@linkplain Buf#send() Sending} a composite buffer implies sending all of its constituent buffers. + * {@linkplain Buffer#send() Sending} a composite buffer implies sending all of its constituent buffers. * For sending to be possible, both the composite buffer itself, and all of its constituent buffers, must be in an * {@linkplain Rc#isOwned() owned state}. * This means that the composite buffer must be the only reference to the constituent buffers. *

    - * All of the constituent buffers must have the same {@linkplain Buf#order() byte order}. + * All of the constituent buffers must have the same {@linkplain Buffer#order() byte order}. * An exception will be thrown if you attempt to compose buffers that have different byte orders, * and changing the byte order of the constituent buffers so they become inconsistent after construction, * will result in unspecified behaviour. @@ -99,16 +99,17 @@ public interface Allocator extends AutoCloseable { *

    * It is not a requirement that the buffers have the same size. *

    - * It is not a requirement that the buffers are allocated by this allocator, but if {@link Buf#ensureWritable(int)} - * is called on the composed buffer, and the composed buffer needs to be expanded, then this allocator instance - * will be used for allocation the extra memory. + * It is not a requirement that the buffers are allocated by this allocator, but if + * {@link Buffer#ensureWritable(int)} is called on the composed buffer, and the composed buffer needs to be + * expanded, then this allocator instance will be used for allocation the extra memory. * * @param bufs The buffers to compose into a single buffer view. * @return A buffer composed of, and backed by, the given buffers. - * @throws IllegalArgumentException if the given buffers have an inconsistent {@linkplain Buf#order() byte order}. + * @throws IllegalArgumentException if the given buffers have an inconsistent + * {@linkplain Buffer#order() byte order}. */ - default Buf compose(Deref... bufs) { - return new CompositeBuf(this, bufs); + default Buffer compose(Deref... bufs) { + return new CompositeBuffer(this, bufs); } /** @@ -122,13 +123,13 @@ public interface Allocator extends AutoCloseable { * extension buffer. * @param extension The buffer to extend the composite buffer with. */ - static void extend(Buf composite, Buf extension) { + static void extend(Buffer composite, Buffer extension) { if (!isComposite(composite)) { throw new IllegalArgumentException( "Expected the first buffer to be a composite buffer, " + "but it is a " + composite.getClass() + " buffer: " + composite + '.'); } - CompositeBuf buf = (CompositeBuf) composite; + CompositeBuffer buf = (CompositeBuffer) composite; buf.extendWith(extension); } @@ -137,8 +138,8 @@ public interface Allocator extends AutoCloseable { * @param composite The buffer to check. * @return {@code true} if the given buffer was created with {@link #compose(Deref...)}, {@code false} otherwise. */ - static boolean isComposite(Buf composite) { - return composite.getClass() == CompositeBuf.class; + static boolean isComposite(Buffer composite) { + return composite.getClass() == CompositeBuffer.class; } /** @@ -149,19 +150,19 @@ public interface Allocator extends AutoCloseable { default void close() { } - static Allocator heap() { - return new ManagedAllocator(MemoryManager.getHeapMemoryManager(), Statics.CLEANER); + static BufferAllocator heap() { + return new ManagedBufferAllocator(MemoryManager.getHeapMemoryManager(), Statics.CLEANER); } - static Allocator direct() { - return new ManagedAllocator(MemoryManager.getNativeMemoryManager(), Statics.CLEANER); + static BufferAllocator direct() { + return new ManagedBufferAllocator(MemoryManager.getNativeMemoryManager(), Statics.CLEANER); } - static Allocator pooledHeap() { + static BufferAllocator pooledHeap() { return new SizeClassedMemoryPool(MemoryManager.getHeapMemoryManager()); } - static Allocator pooledDirect() { + static BufferAllocator pooledDirect() { return new SizeClassedMemoryPool(MemoryManager.getNativeMemoryManager()); } } diff --git a/src/main/java/io/netty/buffer/api/BufHolder.java b/src/main/java/io/netty/buffer/api/BufferHolder.java similarity index 58% rename from src/main/java/io/netty/buffer/api/BufHolder.java rename to src/main/java/io/netty/buffer/api/BufferHolder.java index cd039a9..13f5c01 100644 --- a/src/main/java/io/netty/buffer/api/BufHolder.java +++ b/src/main/java/io/netty/buffer/api/BufferHolder.java @@ -22,42 +22,42 @@ import static io.netty.buffer.api.Statics.findVarHandle; import static java.lang.invoke.MethodHandles.lookup; /** - * The {@link BufHolder} is an abstract class that simplifies the implementation of objects that themselves contain - * a {@link Buf} instance. + * The {@link BufferHolder} is an abstract class that simplifies the implementation of objects that themselves contain + * a {@link Buffer} instance. *

    - * The {@link BufHolder} can only hold on to a single buffer, so objects and classes that need to hold on to multiple - * buffers will have to do their implementation from scratch, though they can use the code of the {@link BufHolder} as - * inspiration. + * The {@link BufferHolder} can only hold on to a single buffer, so objects and classes that need to hold on to multiple + * buffers will have to do their implementation from scratch, though they can use the code of the {@link BufferHolder} + * as inspiration. *

    - * If you just want an object that is a reference to a buffer, then the {@link BufRef} can be used for that purpose. + * If you just want an object that is a reference to a buffer, then the {@link BufferRef} can be used for that purpose. * If you have an advanced use case where you wish to implement {@link Rc}, and tightly control lifetimes, then * {@link RcSupport} can be of help. * - * @param The concrete {@link BufHolder} type. + * @param The concrete {@link BufferHolder} type. */ -public abstract class BufHolder> implements Rc { - private static final VarHandle BUF = findVarHandle(lookup(), BufHolder.class, "buf", Buf.class); - private Buf buf; +public abstract class BufferHolder> implements Rc { + private static final VarHandle BUF = findVarHandle(lookup(), BufferHolder.class, "buf", Buffer.class); + private Buffer buf; /** - * Create a new {@link BufHolder} to hold the given {@linkplain Buf buffer}. + * Create a new {@link BufferHolder} to hold the given {@linkplain Buffer buffer}. *

    * Note: this increases the reference count of the given buffer. * - * @param buf The {@linkplain Buf buffer} to be held by this holder. + * @param buf The {@linkplain Buffer buffer} to be held by this holder. */ - protected BufHolder(Buf buf) { + protected BufferHolder(Buffer buf) { this.buf = Objects.requireNonNull(buf, "The buffer cannot be null.").acquire(); } /** - * Create a new {@link BufHolder} to hold the {@linkplain Buf buffer} received from the given {@link Send}. + * Create a new {@link BufferHolder} to hold the {@linkplain Buffer buffer} received from the given {@link Send}. *

    - * The {@link BufHolder} will then be holding exclusive ownership of the buffer. + * The {@link BufferHolder} will then be holding exclusive ownership of the buffer. * - * @param send The {@linkplain Buf buffer} to be held by this holder. + * @param send The {@linkplain Buffer buffer} to be held by this holder. */ - protected BufHolder(Send send) { + protected BufferHolder(Send send) { buf = Objects.requireNonNull(send, "The send cannot be null.").receive(); } @@ -90,28 +90,28 @@ public abstract class BufHolder> implements Rc { } /** - * Called when a {@linkplain #send() sent} {@link BufHolder} is received by the recipient. - * The {@link BufHolder} should return a new concrete instance, that wraps the given {@link Buf} object. + * Called when a {@linkplain #send() sent} {@link BufferHolder} is received by the recipient. + * The {@link BufferHolder} should return a new concrete instance, that wraps the given {@link Buffer} object. * - * @param buf The {@link Buf} that is {@linkplain Send#receive() received} by the recipient, - * and needs to be wrapped in a new {@link BufHolder} instance. - * @return A new {@linkplain T buffer holder} instance, containing the given {@linkplain Buf buffer}. + * @param buf The {@link Buffer} that is {@linkplain Send#receive() received} by the recipient, + * and needs to be wrapped in a new {@link BufferHolder} instance. + * @return A new {@linkplain T buffer holder} instance, containing the given {@linkplain Buffer buffer}. */ - protected abstract T receive(Buf buf); + protected abstract T receive(Buffer buf); /** * Replace the underlying referenced buffer with the given buffer. *

    - * This method is protected to permit advanced use cases of {@link BufHolder} sub-class implementations. + * This method is protected to permit advanced use cases of {@link BufferHolder} sub-class implementations. *

    * Note: this method decreases the reference count of the current buffer, * and increases the reference count of the new buffer. *

    * The buffer assignment is performed using a plain store. * - * @param newBuf The new {@link Buf} instance that is replacing the currently held buffer. + * @param newBuf The new {@link Buffer} instance that is replacing the currently held buffer. */ - protected final void replaceBuf(Buf newBuf) { + protected final void replaceBuf(Buffer newBuf) { try (var ignore = buf) { buf = newBuf.acquire(); } @@ -120,16 +120,16 @@ public abstract class BufHolder> implements Rc { /** * Replace the underlying referenced buffer with the given buffer. *

    - * This method is protected to permit advanced use cases of {@link BufHolder} sub-class implementations. + * This method is protected to permit advanced use cases of {@link BufferHolder} sub-class implementations. *

    * Note: this method decreases the reference count of the current buffer, * and takes exclusive ownership of the sent buffer. *

    * The buffer assignment is performed using a plain store. * - * @param send The new {@link Buf} instance that is replacing the currently held buffer. + * @param send The new {@link Buffer} instance that is replacing the currently held buffer. */ - protected final void replaceBuf(Send send) { + protected final void replaceBuf(Send send) { try (var ignore = buf) { buf = send.receive(); } @@ -138,56 +138,56 @@ public abstract class BufHolder> implements Rc { /** * Replace the underlying referenced buffer with the given buffer. *

    - * This method is protected to permit advanced use cases of {@link BufHolder} sub-class implementations. + * This method is protected to permit advanced use cases of {@link BufferHolder} sub-class implementations. *

    * Note: this method decreases the reference count of the current buffer, * and increases the reference count of the new buffer. *

    * The buffer assignment is performed using a volatile store. * - * @param newBuf The new {@link Buf} instance that is replacing the currently held buffer. + * @param newBuf The new {@link Buffer} instance that is replacing the currently held buffer. */ - protected final void replaceBufVolatile(Buf newBuf) { - var prev = (Buf) BUF.getAndSet(this, newBuf.acquire()); + protected final void replaceBufVolatile(Buffer newBuf) { + var prev = (Buffer) BUF.getAndSet(this, newBuf.acquire()); prev.close(); } /** * Replace the underlying referenced buffer with the given buffer. *

    - * This method is protected to permit advanced use cases of {@link BufHolder} sub-class implementations. + * This method is protected to permit advanced use cases of {@link BufferHolder} sub-class implementations. *

    * Note: this method decreases the reference count of the current buffer, * and takes exclusive ownership of the sent buffer. *

    * The buffer assignment is performed using a volatile store. * - * @param send The {@link Send} with the new {@link Buf} instance that is replacing the currently held buffer. + * @param send The {@link Send} with the new {@link Buffer} instance that is replacing the currently held buffer. */ - protected final void replaceBufVolatile(Send send) { - var prev = (Buf) BUF.getAndSet(this, send.receive()); + protected final void replaceBufVolatile(Send send) { + var prev = (Buffer) BUF.getAndSet(this, send.receive()); prev.close(); } /** - * Access the held {@link Buf} instance. + * Access the held {@link Buffer} instance. *

    * The access is performed using a plain load. * - * @return The {@link Buf} instance being held by this {@linkplain T buffer holder}. + * @return The {@link Buffer} instance being held by this {@linkplain T buffer holder}. */ - protected final Buf getBuf() { + protected final Buffer getBuf() { return buf; } /** - * Access the held {@link Buf} instance. + * Access the held {@link Buffer} instance. *

    * The access is performed using a volatile load. * - * @return The {@link Buf} instance being held by this {@linkplain T buffer holder}. + * @return The {@link Buffer} instance being held by this {@linkplain T buffer holder}. */ - protected final Buf getBufVolatile() { - return (Buf) BUF.getVolatile(this); + protected final Buffer getBufVolatile() { + return (Buffer) BUF.getVolatile(this); } } diff --git a/src/main/java/io/netty/buffer/api/BufRef.java b/src/main/java/io/netty/buffer/api/BufferRef.java similarity index 71% rename from src/main/java/io/netty/buffer/api/BufRef.java rename to src/main/java/io/netty/buffer/api/BufferRef.java index 2884a23..2c2ee97 100644 --- a/src/main/java/io/netty/buffer/api/BufRef.java +++ b/src/main/java/io/netty/buffer/api/BufferRef.java @@ -20,16 +20,16 @@ import java.lang.invoke.VarHandle; /** * A mutable reference to a buffer. */ -public final class BufRef extends BufHolder { +public final class BufferRef extends BufferHolder { /** - * Create a reference to the given {@linkplain Buf buffer}. + * Create a reference to the given {@linkplain Buffer buffer}. * This increments the reference count of the buffer. * * @param buf The buffer to reference. */ - public BufRef(Buf buf) { + public BufferRef(Buffer buf) { super(buf); - // BufRef is meant to be atomic, so we need to add a fence to get the semantics of a volatile store. + // BufferRef is meant to be atomic, so we need to add a fence to get the semantics of a volatile store. VarHandle.fullFence(); } @@ -38,15 +38,15 @@ public final class BufRef extends BufHolder { * * @param send The {@linkplain Send sent} buffer to take ownership of. */ - public BufRef(Send send) { + public BufferRef(Send send) { super(send); - // BufRef is meant to be atomic, so we need to add a fence to get the semantics of a volatile store. + // BufferRef is meant to be atomic, so we need to add a fence to get the semantics of a volatile store. VarHandle.fullFence(); } @Override - protected BufRef receive(Buf buf) { - return new BufRef(buf); + protected BufferRef receive(Buffer buf) { + return new BufferRef(buf); } /** @@ -57,9 +57,9 @@ public final class BufRef extends BufHolder { *

    * The buffer assignment is performed using a volatile store. * - * @param newBuf The new {@link Buf} instance that is replacing the currently held buffer. + * @param newBuf The new {@link Buffer} instance that is replacing the currently held buffer. */ - public void replace(Buf newBuf) { + public void replace(Buffer newBuf) { replaceBufVolatile(newBuf); } @@ -71,9 +71,9 @@ public final class BufRef extends BufHolder { *

    * The buffer assignment is performed using a volatile store. * - * @param send The {@link Send} with the new {@link Buf} instance that is replacing the currently held buffer. + * @param send The {@link Send} with the new {@link Buffer} instance that is replacing the currently held buffer. */ - public void replace(Send send) { + public void replace(Send send) { replaceBufVolatile(send); } @@ -82,7 +82,7 @@ public final class BufRef extends BufHolder { * * @return The buffer held by the reference. */ - public Buf contents() { + public Buffer contents() { return getBufVolatile(); } } diff --git a/src/main/java/io/netty/buffer/api/CleanerPooledDrop.java b/src/main/java/io/netty/buffer/api/CleanerPooledDrop.java index 38c1e6a..be8621f 100644 --- a/src/main/java/io/netty/buffer/api/CleanerPooledDrop.java +++ b/src/main/java/io/netty/buffer/api/CleanerPooledDrop.java @@ -24,24 +24,24 @@ import static io.netty.buffer.api.Statics.CLEANER; import static io.netty.buffer.api.Statics.findVarHandle; import static java.lang.invoke.MethodHandles.lookup; -class CleanerPooledDrop implements Drop { +class CleanerPooledDrop implements Drop { private static final VarHandle CLEANABLE = findVarHandle(lookup(), CleanerPooledDrop.class, "cleanable", GatedCleanable.class); private final SizeClassedMemoryPool pool; private final MemoryManager manager; - private final Drop delegate; + private final Drop delegate; @SuppressWarnings("unused") private volatile GatedCleanable cleanable; CleanerPooledDrop(SizeClassedMemoryPool pool, MemoryManager manager, - Drop delegate) { + Drop delegate) { this.pool = pool; this.manager = manager; this.delegate = delegate; } @Override - public void drop(Buf buf) { + public void drop(Buffer buf) { GatedCleanable c = (GatedCleanable) CLEANABLE.getAndSet(this, null); if (c != null) { c.clean(); @@ -49,7 +49,7 @@ class CleanerPooledDrop implements Drop { } @Override - public void attach(Buf buf) { + public void attach(Buffer buf) { // Unregister old cleanable, if any, to avoid uncontrolled build-up. GatedCleanable c = (GatedCleanable) CLEANABLE.getAndSet(this, null); if (c != null) { @@ -60,11 +60,11 @@ class CleanerPooledDrop implements Drop { var pool = this.pool; var mem = manager.unwrapRecoverableMemory(buf); var delegate = this.delegate; - WeakReference ref = new WeakReference<>(buf); + WeakReference ref = new WeakReference<>(buf); AtomicBoolean gate = new AtomicBoolean(true); cleanable = new GatedCleanable(gate, CLEANER.register(this, () -> { if (gate.getAndSet(false)) { - Buf b = ref.get(); + Buffer b = ref.get(); if (b == null) { pool.recoverMemory(mem); } else { diff --git a/src/main/java/io/netty/buffer/api/ComponentProcessor.java b/src/main/java/io/netty/buffer/api/ComponentProcessor.java index 53dd1cf..1d4a832 100644 --- a/src/main/java/io/netty/buffer/api/ComponentProcessor.java +++ b/src/main/java/io/netty/buffer/api/ComponentProcessor.java @@ -18,8 +18,9 @@ package io.netty.buffer.api; import java.nio.ByteBuffer; /** - * This interface contain a collection of APIs used in the {@link Buf#forEachReadable(int, ReadableComponentProcessor)} - * and {@link Buf#forEachWritable(int, WritableComponentProcessor)} methods. + * This interface contain a collection of APIs used in the + * {@link Buffer#forEachReadable(int, ReadableComponentProcessor)} and + * {@link Buffer#forEachWritable(int, WritableComponentProcessor)} methods. */ public interface ComponentProcessor { /** @@ -29,14 +30,14 @@ public interface ComponentProcessor { interface ReadableComponentProcessor extends ComponentProcessor { /** * Process the given component at the given index in the - * {@link Buf#forEachReadable(int, ReadableComponentProcessor) iteration}. + * {@link Buffer#forEachReadable(int, ReadableComponentProcessor) iteration}. *

    * The component object itself is only valid during this call, but the {@link ByteBuffer byte buffers}, arrays, * and native address pointers obtained from it, will be valid until any - * {@link Buf#isOwned() ownership} requiring operation is performed on the buffer. + * {@link Buffer#isOwned() ownership} requiring operation is performed on the buffer. * * @param index The current index of the given buffer component, based on the initial index passed to the - * {@link Buf#forEachReadable(int, ReadableComponentProcessor)} method. + * {@link Buffer#forEachReadable(int, ReadableComponentProcessor)} method. * @param component The current buffer component being processed. * @return {@code true} if the iteration should continue and more components should be processed, otherwise * {@code false} to stop the iteration early. @@ -51,14 +52,14 @@ public interface ComponentProcessor { interface WritableComponentProcessor extends ComponentProcessor { /** * Process the given component at the given index in the - * {@link Buf#forEachWritable(int, WritableComponentProcessor)} iteration}. + * {@link Buffer#forEachWritable(int, WritableComponentProcessor)} iteration}. *

    * The component object itself is only valid during this call, but the {@link ByteBuffer byte buffers}, arrays, * and native address pointers obtained from it, will be valid until any - * {@link Buf#isOwned() ownership} requiring operation is performed on the buffer. + * {@link Buffer#isOwned() ownership} requiring operation is performed on the buffer. * * @param index The current index of the given buffer component, based on the initial index passed to the - * {@link Buf#forEachWritable(int, WritableComponentProcessor)} method. + * {@link Buffer#forEachWritable(int, WritableComponentProcessor)} method. * @param component The current buffer component being processed. * @return {@code true} if the iteration should continue and more components should be processed, otherwise * {@code false} to stop the iteration early. @@ -68,7 +69,7 @@ public interface ComponentProcessor { /** * A view onto the buffer component being processed in a given iteration of - * {@link Buf#forEachReadable(int, ReadableComponentProcessor)}. + * {@link Buffer#forEachReadable(int, ReadableComponentProcessor)}. */ interface ReadableComponent { @@ -116,7 +117,8 @@ public interface ComponentProcessor { * Get a {@link ByteBuffer} instance for this memory component. *

    * Note that the {@link ByteBuffer} is read-only, to prevent write accesses to the memory, - * when the buffer component is obtained through {@link Buf#forEachReadable(int, ReadableComponentProcessor)}. + * when the buffer component is obtained through + * {@link Buffer#forEachReadable(int, ReadableComponentProcessor)}. * * @return A new {@link ByteBuffer}, with its own position and limit, for this memory component. */ @@ -126,7 +128,7 @@ public interface ComponentProcessor { /** * A view onto the buffer component being processed in a given iteration of - * {@link Buf#forEachWritable(int, WritableComponentProcessor)}. + * {@link Buffer#forEachWritable(int, WritableComponentProcessor)}. */ interface WritableComponent { diff --git a/src/main/java/io/netty/buffer/api/CompositeBuf.java b/src/main/java/io/netty/buffer/api/CompositeBuffer.java similarity index 86% rename from src/main/java/io/netty/buffer/api/CompositeBuf.java rename to src/main/java/io/netty/buffer/api/CompositeBuffer.java index 0188d5f..572abb3 100644 --- a/src/main/java/io/netty/buffer/api/CompositeBuf.java +++ b/src/main/java/io/netty/buffer/api/CompositeBuffer.java @@ -27,24 +27,24 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Stream; -final class CompositeBuf extends RcSupport implements Buf { +final class CompositeBuffer extends RcSupport implements Buffer { /** * The max array size is JVM implementation dependant, but most seem to settle on {@code Integer.MAX_VALUE - 8}. * We set the max composite buffer capacity to the same, since it would otherwise be impossible to create a * non-composite copy of the buffer. */ private static final int MAX_CAPACITY = Integer.MAX_VALUE - 8; - private static final Drop COMPOSITE_DROP = buf -> { - for (Buf b : buf.bufs) { + private static final Drop COMPOSITE_DROP = buf -> { + for (Buffer b : buf.bufs) { b.close(); } buf.makeInaccessible(); }; - private final Allocator allocator; - private final TornBufAccessors tornBufAccessors; + private final BufferAllocator allocator; + private final TornBufferAccessors tornBufAccessors; private final boolean isSendable; - private Buf[] bufs; + private Buffer[] bufs; private int[] offsets; // The offset, for the composite buffer, where each constituent buffer starts. private int capacity; private int roff; @@ -54,11 +54,11 @@ final class CompositeBuf extends RcSupport implements Buf { private boolean closed; private boolean readOnly; - CompositeBuf(Allocator allocator, Deref[] refs) { + CompositeBuffer(BufferAllocator allocator, Deref[] refs) { this(allocator, true, filterExternalBufs(refs), COMPOSITE_DROP, false); } - private static Buf[] filterExternalBufs(Deref[] refs) { + private static Buffer[] filterExternalBufs(Deref[] refs) { // We filter out all zero-capacity buffers because they wouldn't contribute to the composite buffer anyway, // and also, by ensuring that all constituent buffers contribute to the size of the composite buffer, // we make sure that the number of composite buffers will never become greater than the number of bytes in @@ -66,16 +66,16 @@ final class CompositeBuf extends RcSupport implements Buf { // This restriction guarantees that methods like countComponents, forEachReadable and forEachWritable, // will never overflow their component counts. // Allocating a new array unconditionally also prevents external modification of the array. - Buf[] bufs = Arrays.stream(refs) - .map(r -> r.get()) // Increments reference counts. - .filter(CompositeBuf::discardEmpty) - .flatMap(CompositeBuf::flattenBuffer) - .toArray(Buf[]::new); + Buffer[] bufs = Arrays.stream(refs) + .map(r -> r.get()) // Increments reference counts. + .filter(CompositeBuffer::discardEmpty) + .flatMap(CompositeBuffer::flattenBuffer) + .toArray(Buffer[]::new); // Make sure there are no duplicates among the buffers. - Set duplicatesCheck = Collections.newSetFromMap(new IdentityHashMap<>()); + Set duplicatesCheck = Collections.newSetFromMap(new IdentityHashMap<>()); duplicatesCheck.addAll(Arrays.asList(bufs)); if (duplicatesCheck.size() < bufs.length) { - for (Buf buf : bufs) { + for (Buffer buf : bufs) { buf.close(); // Undo the increment we did with Deref.get(). } throw new IllegalArgumentException( @@ -84,7 +84,7 @@ final class CompositeBuf extends RcSupport implements Buf { return bufs; } - private static boolean discardEmpty(Buf buf) { + private static boolean discardEmpty(Buffer buf) { if (buf.capacity() > 0) { return true; } else { @@ -95,12 +95,12 @@ final class CompositeBuf extends RcSupport implements Buf { } } - private static Stream flattenBuffer(Buf buf) { - if (buf instanceof CompositeBuf) { + private static Stream flattenBuffer(Buffer buf) { + if (buf instanceof CompositeBuffer) { // Extract components and move our reference count from the composite onto the components. - var composite = (CompositeBuf) buf; + var composite = (CompositeBuffer) buf; var bufs = composite.bufs; - for (Buf b : bufs) { + for (Buffer b : bufs) { b.acquire(); } buf.close(); // Important: acquire on components *before* closing composite. @@ -109,20 +109,20 @@ final class CompositeBuf extends RcSupport implements Buf { return Stream.of(buf); } - private CompositeBuf(Allocator allocator, boolean isSendable, Buf[] bufs, Drop drop, - boolean acquireBufs) { + private CompositeBuffer(BufferAllocator allocator, boolean isSendable, Buffer[] bufs, Drop drop, + boolean acquireBufs) { super(drop); this.allocator = allocator; this.isSendable = isSendable; if (acquireBufs) { - for (Buf buf : bufs) { + for (Buffer buf : bufs) { buf.acquire(); } } try { if (bufs.length > 0) { ByteOrder targetOrder = bufs[0].order(); - for (Buf buf : bufs) { + for (Buffer buf : bufs) { if (buf.order() != targetOrder) { throw new IllegalArgumentException("Constituent buffers have inconsistent byte order."); } @@ -130,7 +130,7 @@ final class CompositeBuf extends RcSupport implements Buf { order = bufs[0].order(); boolean targetReadOnly = bufs[0].readOnly(); - for (Buf buf : bufs) { + for (Buffer buf : bufs) { if (buf.readOnly() != targetReadOnly) { throw new IllegalArgumentException("Constituent buffers have inconsistent read-only state."); } @@ -141,11 +141,11 @@ final class CompositeBuf extends RcSupport implements Buf { } this.bufs = bufs; computeBufferOffsets(); - tornBufAccessors = new TornBufAccessors(this); + tornBufAccessors = new TornBufferAccessors(this); } catch (Exception e) { // Always close bufs on exception, regardless of acquireBufs value. // If acquireBufs is false, it just means the ref count increments happened prior to this constructor call. - for (Buf buf : bufs) { + for (Buffer buf : bufs) { buf.close(); } throw e; @@ -157,7 +157,7 @@ final class CompositeBuf extends RcSupport implements Buf { int woff = 0; int roff = 0; boolean woffMidpoint = false; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { if (buf.writableBytes() == 0) { woff += buf.capacity(); } else if (!woffMidpoint) { @@ -170,7 +170,7 @@ final class CompositeBuf extends RcSupport implements Buf { } } boolean roffMidpoint = false; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { if (buf.readableBytes() == 0 && buf.writableBytes() == 0) { roff += buf.capacity(); } else if (!roffMidpoint) { @@ -206,14 +206,14 @@ final class CompositeBuf extends RcSupport implements Buf { @Override public String toString() { - return "Buf[roff:" + roff + ", woff:" + woff + ", cap:" + capacity + ']'; + return "Buffer[roff:" + roff + ", woff:" + woff + ", cap:" + capacity + ']'; } @Override - public Buf order(ByteOrder order) { + public Buffer order(ByteOrder order) { if (this.order != order) { this.order = order; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { buf.order(order); } } @@ -236,10 +236,10 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf readerOffset(int index) { + public Buffer readerOffset(int index) { prepRead(index, 0); int indexLeft = index; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { buf.readerOffset(Math.min(indexLeft, buf.capacity())); indexLeft = Math.max(0, indexLeft - buf.capacity()); } @@ -253,10 +253,10 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writerOffset(int index) { + public Buffer writerOffset(int index) { checkWriteBounds(index, 0); int indexLeft = index; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { buf.writerOffset(Math.min(indexLeft, buf.capacity())); indexLeft = Math.max(0, indexLeft - buf.capacity()); } @@ -265,8 +265,8 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf fill(byte value) { - for (Buf buf : bufs) { + public Buffer fill(byte value) { + for (Buffer buf : bufs) { buf.fill(value); } return this; @@ -278,8 +278,8 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf readOnly(boolean readOnly) { - for (Buf buf : bufs) { + public Buffer readOnly(boolean readOnly) { + for (Buffer buf : bufs) { buf.readOnly(readOnly); } this.readOnly = readOnly; @@ -292,24 +292,24 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf slice(int offset, int length) { + public Buffer slice(int offset, int length) { checkWriteBounds(offset, length); if (offset < 0 || length < 0) { throw new IllegalArgumentException( "Offset and length cannot be negative, but offset was " + offset + ", and length was " + length + '.'); } - Buf choice = (Buf) chooseBuffer(offset, 0); - Buf[] slices = null; + Buffer choice = (Buffer) chooseBuffer(offset, 0); + Buffer[] slices = null; acquire(); // Increase reference count of the original composite buffer. - Drop drop = obj -> { + Drop drop = obj -> { close(); // Decrement the reference count of the original composite buffer. COMPOSITE_DROP.drop(obj); }; try { if (length > 0) { - slices = new Buf[bufs.length]; + slices = new Buffer[bufs.length]; int off = subOffset; int cap = length; int i; @@ -323,17 +323,17 @@ final class CompositeBuf extends RcSupport implements Buf { slices = Arrays.copyOf(slices, i); } else { // Specialize for length == 0, since we must slice from at least one constituent buffer. - slices = new Buf[] { choice.slice(subOffset, 0) }; + slices = new Buffer[] { choice.slice(subOffset, 0) }; } - return new CompositeBuf(allocator, false, slices, drop, true); + return new CompositeBuffer(allocator, false, slices, drop, true); } catch (Throwable throwable) { // We called acquire prior to the try-clause. We need to undo that if we're not creating a composite buffer: close(); throw throwable; } finally { if (slices != null) { - for (Buf slice : slices) { + for (Buffer slice : slices) { if (slice != null) { slice.close(); // Ownership now transfers to the composite buffer. } @@ -363,7 +363,7 @@ final class CompositeBuf extends RcSupport implements Buf { throw indexOutOfBounds(srcPos + length, false); } while (length > 0) { - var buf = (Buf) chooseBuffer(srcPos, 0); + var buf = (Buffer) chooseBuffer(srcPos, 0); int toCopy = Math.min(buf.capacity() - subOffset, length); dest.copyInto(buf, subOffset, destPos, toCopy); srcPos += toCopy; @@ -374,11 +374,11 @@ final class CompositeBuf extends RcSupport implements Buf { @FunctionalInterface private interface CopyInto { - void copyInto(Buf src, int srcPos, int destPos, int length); + void copyInto(Buffer src, int srcPos, int destPos, int length); } @Override - public void copyInto(int srcPos, Buf dest, int destPos, int length) { + public void copyInto(int srcPos, Buffer dest, int destPos, int length) { if (length < 0) { throw new IndexOutOfBoundsException("Length cannot be negative: " + length + '.'); } @@ -422,7 +422,7 @@ final class CompositeBuf extends RcSupport implements Buf { } int startBufferIndex = searchOffsets(fromOffset); int off = fromOffset - offsets[startBufferIndex]; - Buf startBuf = bufs[startBufferIndex]; + Buffer startBuf = bufs[startBufferIndex]; ByteCursor startCursor = startBuf.openCursor(off, Math.min(startBuf.capacity() - off, length)); return new ByteCursor() { int index = fromOffset; @@ -484,7 +484,7 @@ final class CompositeBuf extends RcSupport implements Buf { private void nextCursor() { bufferIndex++; - Buf nextBuf = bufs[bufferIndex]; + Buffer nextBuf = bufs[bufferIndex]; cursor = nextBuf.openCursor(0, Math.min(nextBuf.capacity(), bytesLeft())); initOffset = 0; } @@ -523,7 +523,7 @@ final class CompositeBuf extends RcSupport implements Buf { } int startBufferIndex = searchOffsets(fromOffset); int off = fromOffset - offsets[startBufferIndex]; - Buf startBuf = bufs[startBufferIndex]; + Buffer startBuf = bufs[startBufferIndex]; ByteCursor startCursor = startBuf.openReverseCursor(off, Math.min(off + 1, length)); return new ByteCursor() { int index = fromOffset; @@ -585,7 +585,7 @@ final class CompositeBuf extends RcSupport implements Buf { private void nextCursor() { bufferIndex--; - Buf nextBuf = bufs[bufferIndex]; + Buffer nextBuf = bufs[bufferIndex]; int length = Math.min(nextBuf.capacity(), bytesLeft()); int offset = nextBuf.capacity() - 1; cursor = nextBuf.openReverseCursor(offset, length); @@ -632,23 +632,23 @@ final class CompositeBuf extends RcSupport implements Buf { // Let's see if we can solve some or all of the requested size with compaction. // We always compact as much as is possible, regardless of size. This amortizes our work. int compactableBuffers = 0; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { if (buf.capacity() != buf.readerOffset()) { break; } compactableBuffers++; } if (compactableBuffers > 0) { - Buf[] compactable; + Buffer[] compactable; if (compactableBuffers < bufs.length) { - compactable = new Buf[compactableBuffers]; + compactable = new Buffer[compactableBuffers]; System.arraycopy(bufs, 0, compactable, 0, compactable.length); System.arraycopy(bufs, compactable.length, bufs, 0, bufs.length - compactable.length); System.arraycopy(compactable, 0, bufs, bufs.length - compactable.length, compactable.length); } else { compactable = bufs; } - for (Buf buf : compactable) { + for (Buffer buf : compactable) { buf.reset(); } computeBufferOffsets(); @@ -660,13 +660,13 @@ final class CompositeBuf extends RcSupport implements Buf { } long newSize = capacity() + (long) size; - Allocator.checkSize(newSize); + BufferAllocator.checkSize(newSize); int growth = size - writableBytes(); - Buf extension = bufs.length == 0? allocator.allocate(growth) : allocator.allocate(growth, order()); + Buffer extension = bufs.length == 0? allocator.allocate(growth) : allocator.allocate(growth, order()); unsafeExtendWith(extension); } - void extendWith(Buf extension) { + void extendWith(Buffer extension) { Objects.requireNonNull(extension, "Extension buffer cannot be null."); if (!isOwned()) { throw new IllegalStateException("This buffer cannot be extended because it is not in an owned state."); @@ -693,22 +693,22 @@ final class CompositeBuf extends RcSupport implements Buf { } long newSize = capacity() + extensionCapacity; - Allocator.checkSize(newSize); + BufferAllocator.checkSize(newSize); - Buf[] restoreTemp = bufs; // We need this to restore our buffer array, in case offset computations fail. + Buffer[] restoreTemp = bufs; // We need this to restore our buffer array, in case offset computations fail. try { - if (extension instanceof CompositeBuf) { + if (extension instanceof CompositeBuffer) { // If the extension is itself a composite buffer, then extend this one by all of the constituent // component buffers. - CompositeBuf compositeExtension = (CompositeBuf) extension; - Buf[] addedBuffers = compositeExtension.bufs; - Set duplicatesCheck = Collections.newSetFromMap(new IdentityHashMap<>()); + CompositeBuffer compositeExtension = (CompositeBuffer) extension; + Buffer[] addedBuffers = compositeExtension.bufs; + Set duplicatesCheck = Collections.newSetFromMap(new IdentityHashMap<>()); duplicatesCheck.addAll(Arrays.asList(bufs)); duplicatesCheck.addAll(Arrays.asList(addedBuffers)); if (duplicatesCheck.size() < bufs.length + addedBuffers.length) { throw extensionDuplicatesException(); } - for (Buf addedBuffer : addedBuffers) { + for (Buffer addedBuffer : addedBuffers) { addedBuffer.acquire(); } int extendAtIndex = bufs.length; @@ -716,7 +716,7 @@ final class CompositeBuf extends RcSupport implements Buf { System.arraycopy(addedBuffers, 0, bufs, extendAtIndex, addedBuffers.length); computeBufferOffsets(); } else { - for (Buf buf : restoreTemp) { + for (Buffer buf : restoreTemp) { if (buf == extension) { throw extensionDuplicatesException(); } @@ -739,37 +739,37 @@ final class CompositeBuf extends RcSupport implements Buf { " as it would cause the buffer to have duplicate constituent buffers."); } - private void unsafeExtendWith(Buf extension) { + private void unsafeExtendWith(Buffer extension) { bufs = Arrays.copyOf(bufs, bufs.length + 1); bufs[bufs.length - 1] = extension; computeBufferOffsets(); } @Override - public Buf bifurcate() { + public Buffer bifurcate() { if (!isOwned()) { throw new IllegalStateException("Cannot bifurcate a buffer that is not owned."); } if (bufs.length == 0) { // Bifurcating a zero-length buffer is trivial. - return new CompositeBuf(allocator, true, bufs, unsafeGetDrop(), true).order(order); + return new CompositeBuffer(allocator, true, bufs, unsafeGetDrop(), true).order(order); } int i = searchOffsets(woff); int off = woff - offsets[i]; - Buf[] bifs = Arrays.copyOf(bufs, off == 0? i : 1 + i); + Buffer[] bifs = Arrays.copyOf(bufs, off == 0? i : 1 + i); bufs = Arrays.copyOfRange(bufs, off == bufs[i].capacity()? 1 + i : i, bufs.length); if (off > 0 && bifs.length > 0 && off < bifs[bifs.length - 1].capacity()) { bifs[bifs.length - 1] = bufs[0].bifurcate(); } computeBufferOffsets(); try { - var compositeBuf = new CompositeBuf(allocator, true, bifs, unsafeGetDrop(), true); + var compositeBuf = new CompositeBuffer(allocator, true, bifs, unsafeGetDrop(), true); compositeBuf.order = order; // Preserve byte order even if bifs array is empty. return compositeBuf; } finally { // Drop our references to the buffers in the bifs array. They belong to the new composite buffer now. - for (Buf bif : bifs) { + for (Buffer bif : bifs) { bif.close(); } } @@ -810,7 +810,7 @@ final class CompositeBuf extends RcSupport implements Buf { @Override public int countComponents() { int sum = 0; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { sum += buf.countComponents(); } return sum; @@ -819,7 +819,7 @@ final class CompositeBuf extends RcSupport implements Buf { @Override public int countReadableComponents() { int sum = 0; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { sum += buf.countReadableComponents(); } return sum; @@ -828,7 +828,7 @@ final class CompositeBuf extends RcSupport implements Buf { @Override public int countWritableComponents() { int sum = 0; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { sum += buf.countWritableComponents(); } return sum; @@ -839,7 +839,7 @@ final class CompositeBuf extends RcSupport implements Buf { throws E { checkReadBounds(readerOffset(), Math.max(1, readableBytes())); int visited = 0; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { if (buf.readableBytes() > 0) { int count = buf.forEachReadable(visited + initialIndex, processor); if (count > 0) { @@ -858,7 +858,7 @@ final class CompositeBuf extends RcSupport implements Buf { throws E { checkWriteBounds(writerOffset(), Math.max(1, writableBytes())); int visited = 0; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { if (buf.writableBytes() > 0) { int count = buf.forEachWritable(visited + initialIndex, processor); if (count > 0) { @@ -894,25 +894,25 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeByte(byte value) { + public Buffer writeByte(byte value) { prepWrite(Byte.BYTES).writeByte(value); return this; } @Override - public Buf setByte(int woff, byte value) { + public Buffer setByte(int woff, byte value) { prepWrite(woff, Byte.BYTES).setByte(subOffset, value); return this; } @Override - public Buf writeUnsignedByte(int value) { + public Buffer writeUnsignedByte(int value) { prepWrite(Byte.BYTES).writeUnsignedByte(value); return this; } @Override - public Buf setUnsignedByte(int woff, int value) { + public Buffer setUnsignedByte(int woff, int value) { prepWrite(woff, Byte.BYTES).setUnsignedByte(subOffset, value); return this; } @@ -928,13 +928,13 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeChar(char value) { + public Buffer writeChar(char value) { prepWrite(2).writeChar(value); return this; } @Override - public Buf setChar(int woff, char value) { + public Buffer setChar(int woff, char value) { prepWrite(woff, 2).setChar(subOffset, value); return this; } @@ -960,25 +960,25 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeShort(short value) { + public Buffer writeShort(short value) { prepWrite(Short.BYTES).writeShort(value); return this; } @Override - public Buf setShort(int woff, short value) { + public Buffer setShort(int woff, short value) { prepWrite(woff, Short.BYTES).setShort(subOffset, value); return this; } @Override - public Buf writeUnsignedShort(int value) { + public Buffer writeUnsignedShort(int value) { prepWrite(Short.BYTES).writeUnsignedShort(value); return this; } @Override - public Buf setUnsignedShort(int woff, int value) { + public Buffer setUnsignedShort(int woff, int value) { prepWrite(woff, Short.BYTES).setUnsignedShort(subOffset, value); return this; } @@ -1004,25 +1004,25 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeMedium(int value) { + public Buffer writeMedium(int value) { prepWrite(3).writeMedium(value); return this; } @Override - public Buf setMedium(int woff, int value) { + public Buffer setMedium(int woff, int value) { prepWrite(woff, 3).setMedium(subOffset, value); return this; } @Override - public Buf writeUnsignedMedium(int value) { + public Buffer writeUnsignedMedium(int value) { prepWrite(3).writeUnsignedMedium(value); return this; } @Override - public Buf setUnsignedMedium(int woff, int value) { + public Buffer setUnsignedMedium(int woff, int value) { prepWrite(woff, 3).setUnsignedMedium(subOffset, value); return this; } @@ -1048,25 +1048,25 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeInt(int value) { + public Buffer writeInt(int value) { prepWrite(Integer.BYTES).writeInt(value); return this; } @Override - public Buf setInt(int woff, int value) { + public Buffer setInt(int woff, int value) { prepWrite(woff, Integer.BYTES).setInt(subOffset, value); return this; } @Override - public Buf writeUnsignedInt(long value) { + public Buffer writeUnsignedInt(long value) { prepWrite(Integer.BYTES).writeUnsignedInt(value); return this; } @Override - public Buf setUnsignedInt(int woff, long value) { + public Buffer setUnsignedInt(int woff, long value) { prepWrite(woff, Integer.BYTES).setUnsignedInt(subOffset, value); return this; } @@ -1082,13 +1082,13 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeFloat(float value) { + public Buffer writeFloat(float value) { prepWrite(Float.BYTES).writeFloat(value); return this; } @Override - public Buf setFloat(int woff, float value) { + public Buffer setFloat(int woff, float value) { prepWrite(woff, Float.BYTES).setFloat(subOffset, value); return this; } @@ -1104,13 +1104,13 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeLong(long value) { + public Buffer writeLong(long value) { prepWrite(Long.BYTES).writeLong(value); return this; } @Override - public Buf setLong(int woff, long value) { + public Buffer setLong(int woff, long value) { prepWrite(woff, Long.BYTES).setLong(subOffset, value); return this; } @@ -1126,22 +1126,22 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeDouble(double value) { + public Buffer writeDouble(double value) { prepWrite(Double.BYTES).writeDouble(value); return this; } @Override - public Buf setDouble(int woff, double value) { + public Buffer setDouble(int woff, double value) { prepWrite(woff, Double.BYTES).setDouble(subOffset, value); return this; } // @Override - protected Owned prepareSend() { + protected Owned prepareSend() { @SuppressWarnings("unchecked") - Send[] sends = new Send[bufs.length]; + Send[] sends = new Send[bufs.length]; try { for (int i = 0; i < bufs.length; i++) { sends[i] = bufs[i].send(); @@ -1160,14 +1160,14 @@ final class CompositeBuf extends RcSupport implements Buf { throw throwable; } makeInaccessible(); - return new Owned() { + return new Owned() { @Override - public CompositeBuf transferOwnership(Drop drop) { - Buf[] received = new Buf[sends.length]; + public CompositeBuffer transferOwnership(Drop drop) { + Buffer[] received = new Buffer[sends.length]; for (int i = 0; i < sends.length; i++) { received[i] = sends[i].receive(); } - var composite = new CompositeBuf(allocator, true, received, drop, true); + var composite = new CompositeBuffer(allocator, true, received, drop, true); composite.readOnly = readOnly; drop.attach(composite); return composite; @@ -1198,7 +1198,7 @@ final class CompositeBuf extends RcSupport implements Buf { private boolean allConstituentsAreOwned() { boolean result = true; - for (Buf buf : bufs) { + for (Buffer buf : bufs) { result &= buf.isOwned(); } return result; @@ -1228,13 +1228,13 @@ final class CompositeBuf extends RcSupport implements Buf { buf.setUnsignedByte(subOffset, value); } - private BufAccessors prepRead(int size) { + private BufferAccessors prepRead(int size) { var buf = prepRead(roff, size); roff += size; return buf; } - private BufAccessors prepRead(int index, int size) { + private BufferAccessors prepRead(int index, int size) { checkReadBounds(index, size); return chooseBuffer(index, size); } @@ -1245,13 +1245,13 @@ final class CompositeBuf extends RcSupport implements Buf { } } - private BufAccessors prepWrite(int size) { + private BufferAccessors prepWrite(int size) { var buf = prepWrite(woff, size); woff += size; return buf; } - private BufAccessors prepWrite(int index, int size) { + private BufferAccessors prepWrite(int index, int size) { checkWriteBounds(index, size); return chooseBuffer(index, size); } @@ -1282,7 +1282,7 @@ final class CompositeBuf extends RcSupport implements Buf { return new IllegalStateException("This buffer is read-only."); } - private BufAccessors chooseBuffer(int index, int size) { + private BufferAccessors chooseBuffer(int index, int size) { int i = searchOffsets(index); if (i == bufs.length) { // This happens when the read/write offsets are parked 1 byte beyond the end of the buffer. @@ -1290,7 +1290,7 @@ final class CompositeBuf extends RcSupport implements Buf { return null; } int off = index - offsets[i]; - Buf candidate = bufs[i]; + Buffer candidate = bufs[i]; if (off + size <= candidate.capacity()) { subOffset = off; return candidate; @@ -1299,7 +1299,7 @@ final class CompositeBuf extends RcSupport implements Buf { return tornBufAccessors; } - private BufAccessors choosePassThroughBuffer(int index) { + private BufferAccessors choosePassThroughBuffer(int index) { int i = searchOffsets(index); return bufs[i]; } @@ -1310,10 +1310,10 @@ final class CompositeBuf extends RcSupport implements Buf { } // - private static final class TornBufAccessors implements BufAccessors { - private final CompositeBuf buf; + private static final class TornBufferAccessors implements BufferAccessors { + private final CompositeBuffer buf; - private TornBufAccessors(CompositeBuf buf) { + private TornBufferAccessors(CompositeBuffer buf) { this.buf = buf; } @@ -1338,22 +1338,22 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeByte(byte value) { + public Buffer writeByte(byte value) { throw new AssertionError("Method should not be used."); } @Override - public Buf setByte(int woff, byte value) { + public Buffer setByte(int woff, byte value) { throw new AssertionError("Method should not be used."); } @Override - public Buf writeUnsignedByte(int value) { + public Buffer writeUnsignedByte(int value) { throw new AssertionError("Method should not be used."); } @Override - public Buf setUnsignedByte(int woff, int value) { + public Buffer setUnsignedByte(int woff, int value) { throw new AssertionError("Method should not be used."); } @@ -1376,7 +1376,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeChar(char value) { + public Buffer writeChar(char value) { if (bigEndian()) { write(value >>> 8); write(value & 0xFF); @@ -1388,7 +1388,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf setChar(int woff, char value) { + public Buffer setChar(int woff, char value) { if (bigEndian()) { write(woff, value >>> 8); write(woff + 1, value & 0xFF); @@ -1436,7 +1436,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeShort(short value) { + public Buffer writeShort(short value) { if (bigEndian()) { write(value >>> 8); write(value & 0xFF); @@ -1448,7 +1448,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf setShort(int woff, short value) { + public Buffer setShort(int woff, short value) { if (bigEndian()) { write(woff, value >>> 8); write(woff + 1, value & 0xFF); @@ -1460,7 +1460,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeUnsignedShort(int value) { + public Buffer writeUnsignedShort(int value) { if (bigEndian()) { write(value >>> 8); write(value & 0xFF); @@ -1472,7 +1472,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf setUnsignedShort(int woff, int value) { + public Buffer setUnsignedShort(int woff, int value) { if (bigEndian()) { write(woff, value >>> 8); write(woff + 1, value & 0xFF); @@ -1520,7 +1520,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeMedium(int value) { + public Buffer writeMedium(int value) { if (bigEndian()) { write(value >>> 16); write(value >>> 8 & 0xFF); @@ -1534,7 +1534,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf setMedium(int woff, int value) { + public Buffer setMedium(int woff, int value) { if (bigEndian()) { write(woff, value >>> 16); write(woff + 1, value >>> 8 & 0xFF); @@ -1548,7 +1548,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeUnsignedMedium(int value) { + public Buffer writeUnsignedMedium(int value) { if (bigEndian()) { write(value >>> 16); write(value >>> 8 & 0xFF); @@ -1562,7 +1562,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf setUnsignedMedium(int woff, int value) { + public Buffer setUnsignedMedium(int woff, int value) { if (bigEndian()) { write(woff, value >>> 16); write(woff + 1, value >>> 8 & 0xFF); @@ -1612,7 +1612,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeInt(int value) { + public Buffer writeInt(int value) { if (bigEndian()) { write(value >>> 24); write(value >>> 16 & 0xFF); @@ -1628,7 +1628,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf setInt(int woff, int value) { + public Buffer setInt(int woff, int value) { if (bigEndian()) { write(woff, value >>> 24); write(woff + 1, value >>> 16 & 0xFF); @@ -1644,7 +1644,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeUnsignedInt(long value) { + public Buffer writeUnsignedInt(long value) { if (bigEndian()) { write((int) (value >>> 24)); write((int) (value >>> 16 & 0xFF)); @@ -1660,7 +1660,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf setUnsignedInt(int woff, long value) { + public Buffer setUnsignedInt(int woff, long value) { if (bigEndian()) { write(woff, (int) (value >>> 24)); write(woff + 1, (int) (value >>> 16 & 0xFF)); @@ -1686,12 +1686,12 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeFloat(float value) { + public Buffer writeFloat(float value) { return writeUnsignedInt(Float.floatToRawIntBits(value)); } @Override - public Buf setFloat(int woff, float value) { + public Buffer setFloat(int woff, float value) { return setUnsignedInt(woff, Float.floatToRawIntBits(value)); } @@ -1718,7 +1718,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeLong(long value) { + public Buffer writeLong(long value) { if (bigEndian()) { write((int) (value >>> 56)); write((int) (value >>> 48 & 0xFF)); @@ -1742,7 +1742,7 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf setLong(int woff, long value) { + public Buffer setLong(int woff, long value) { if (bigEndian()) { write(woff, (int) (value >>> 56)); write(woff + 1, (int) (value >>> 48 & 0xFF)); @@ -1776,12 +1776,12 @@ final class CompositeBuf extends RcSupport implements Buf { } @Override - public Buf writeDouble(double value) { + public Buffer writeDouble(double value) { return writeLong(Double.doubleToRawLongBits(value)); } @Override - public Buf setDouble(int woff, double value) { + public Buffer setDouble(int woff, double value) { return setLong(woff, Double.doubleToRawLongBits(value)); } diff --git a/src/main/java/io/netty/buffer/api/ManagedAllocator.java b/src/main/java/io/netty/buffer/api/ManagedBufferAllocator.java similarity index 79% rename from src/main/java/io/netty/buffer/api/ManagedAllocator.java rename to src/main/java/io/netty/buffer/api/ManagedBufferAllocator.java index c3baf3c..85baa45 100644 --- a/src/main/java/io/netty/buffer/api/ManagedAllocator.java +++ b/src/main/java/io/netty/buffer/api/ManagedBufferAllocator.java @@ -19,24 +19,24 @@ import java.lang.ref.Cleaner; import static io.netty.buffer.api.Statics.NO_OP_DROP; -class ManagedAllocator implements Allocator, AllocatorControl { +class ManagedBufferAllocator implements BufferAllocator, AllocatorControl { private final MemoryManager manager; private final Cleaner cleaner; - ManagedAllocator(MemoryManager manager, Cleaner cleaner) { + ManagedBufferAllocator(MemoryManager manager, Cleaner cleaner) { this.manager = manager; this.cleaner = cleaner; } @Override - public Buf allocate(int size) { - Allocator.checkSize(size); + public Buffer allocate(int size) { + BufferAllocator.checkSize(size); return manager.allocateShared(this, size, manager.drop(), cleaner); } @Override - public Object allocateUntethered(Buf originator, int size) { - Allocator.checkSize(size); + public Object allocateUntethered(Buffer originator, int size) { + BufferAllocator.checkSize(size); var buf = manager.allocateShared(this, size, NO_OP_DROP, null); return manager.unwrapRecoverableMemory(buf); } diff --git a/src/main/java/io/netty/buffer/api/MemoryManager.java b/src/main/java/io/netty/buffer/api/MemoryManager.java index d41bea9..c3e6dfd 100644 --- a/src/main/java/io/netty/buffer/api/MemoryManager.java +++ b/src/main/java/io/netty/buffer/api/MemoryManager.java @@ -30,9 +30,9 @@ public interface MemoryManager { } boolean isNative(); - Buf allocateConfined(AllocatorControl alloc, long size, Drop drop, Cleaner cleaner); - Buf allocateShared(AllocatorControl allo, long size, Drop drop, Cleaner cleaner); - Drop drop(); - Object unwrapRecoverableMemory(Buf buf); - Buf recoverMemory(Object recoverableMemory, Drop drop); + Buffer allocateConfined(AllocatorControl alloc, long size, Drop drop, Cleaner cleaner); + Buffer allocateShared(AllocatorControl allo, long size, Drop drop, Cleaner cleaner); + Drop drop(); + Object unwrapRecoverableMemory(Buffer buf); + Buffer recoverMemory(Object recoverableMemory, Drop drop); } diff --git a/src/main/java/io/netty/buffer/api/SizeClassedMemoryPool.java b/src/main/java/io/netty/buffer/api/SizeClassedMemoryPool.java index 8d82b09..08a6949 100644 --- a/src/main/java/io/netty/buffer/api/SizeClassedMemoryPool.java +++ b/src/main/java/io/netty/buffer/api/SizeClassedMemoryPool.java @@ -24,11 +24,11 @@ import java.util.concurrent.ConcurrentLinkedQueue; import static io.netty.buffer.api.Statics.NO_OP_DROP; import static java.lang.invoke.MethodHandles.lookup; -class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop { +class SizeClassedMemoryPool implements BufferAllocator, AllocatorControl, Drop { private static final VarHandle CLOSE = Statics.findVarHandle( lookup(), SizeClassedMemoryPool.class, "closed", boolean.class); private final MemoryManager manager; - private final ConcurrentHashMap>> pool; + private final ConcurrentHashMap>> pool; @SuppressWarnings("unused") private volatile boolean closed; @@ -38,10 +38,10 @@ class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop { } @Override - public Buf allocate(int size) { - Allocator.checkSize(size); + public Buffer allocate(int size) { + BufferAllocator.checkSize(size); var sizeClassPool = getSizeClassPool(size); - Send send = sizeClassPool.poll(); + Send send = sizeClassPool.poll(); if (send != null) { return send.receive() .reset() @@ -56,13 +56,13 @@ class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop { return manager; } - protected Buf createBuf(int size, Drop drop) { + protected Buffer createBuf(int size, Drop drop) { var buf = manager.allocateShared(this, size, drop, null); drop.attach(buf); return buf; } - protected Drop getDrop() { + protected Drop getDrop() { return new CleanerPooledDrop(this, getMemoryManager(), this); } @@ -71,7 +71,7 @@ class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop { if (CLOSE.compareAndSet(this, false, true)) { var capturedExceptions = new ArrayList(4); pool.forEach((k, v) -> { - Send send; + Send send; while ((send = v.poll()) != null) { try { send.receive().close(); @@ -89,7 +89,7 @@ class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop { } @Override - public void drop(Buf buf) { + public void drop(Buffer buf) { if (closed) { dispose(buf); return; @@ -97,7 +97,7 @@ class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop { var sizeClassPool = getSizeClassPool(buf.capacity()); sizeClassPool.offer(buf.send()); if (closed) { - Send send; + Send send; while ((send = sizeClassPool.poll()) != null) { send.receive().close(); } @@ -105,12 +105,12 @@ class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop { } @Override - public Object allocateUntethered(Buf originator, int size) { + public Object allocateUntethered(Buffer originator, int size) { var sizeClassPool = getSizeClassPool(size); - Send send = sizeClassPool.poll(); - Buf untetheredBuf; + Send send = sizeClassPool.poll(); + Buffer untetheredBuf; if (send != null) { - var transfer = (TransferSend) send; + var transfer = (TransferSend) send; var owned = transfer.unsafeUnwrapOwned(); untetheredBuf = owned.transferOwnership(NO_OP_DROP); } else { @@ -127,11 +127,11 @@ class SizeClassedMemoryPool implements Allocator, AllocatorControl, Drop { buf.close(); } - private ConcurrentLinkedQueue> getSizeClassPool(int size) { + private ConcurrentLinkedQueue> getSizeClassPool(int size) { return pool.computeIfAbsent(size, k -> new ConcurrentLinkedQueue<>()); } - private void dispose(Buf buf) { + private void dispose(Buffer buf) { manager.drop().drop(buf); } } diff --git a/src/main/java/io/netty/buffer/api/Statics.java b/src/main/java/io/netty/buffer/api/Statics.java index d42f16b..63a0b42 100644 --- a/src/main/java/io/netty/buffer/api/Statics.java +++ b/src/main/java/io/netty/buffer/api/Statics.java @@ -21,7 +21,7 @@ import java.lang.ref.Cleaner; interface Statics { Cleaner CLEANER = Cleaner.create(); - Drop NO_OP_DROP = buf -> { + Drop NO_OP_DROP = buf -> { }; static VarHandle findVarHandle(Lookup lookup, Class recv, String name, Class type) { diff --git a/src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java b/src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java index b740fbc..797970b 100644 --- a/src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java +++ b/src/main/java/io/netty/buffer/api/memseg/AbstractMemorySegmentManager.java @@ -16,10 +16,10 @@ package io.netty.buffer.api.memseg; import io.netty.buffer.api.AllocatorControl; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.Buffer; import io.netty.buffer.api.Drop; import io.netty.buffer.api.MemoryManager; -import io.netty.buffer.api.memseg.MemSegBuf.RecoverableMemory; +import io.netty.buffer.api.memseg.MemSegBuffer.RecoverableMemory; import jdk.incubator.foreign.MemorySegment; import java.lang.ref.Cleaner; @@ -29,38 +29,38 @@ public abstract class AbstractMemorySegmentManager implements MemoryManager { public abstract boolean isNative(); @Override - public Buf allocateConfined(AllocatorControl alloc, long size, Drop drop, Cleaner cleaner) { + public Buffer allocateConfined(AllocatorControl alloc, long size, Drop drop, Cleaner cleaner) { var segment = createSegment(size); if (cleaner != null) { segment = segment.registerCleaner(cleaner); } - return new MemSegBuf(segment, convert(drop), alloc); + return new MemSegBuffer(segment, convert(drop), alloc); } @Override - public Buf allocateShared(AllocatorControl alloc, long size, Drop drop, Cleaner cleaner) { + public Buffer allocateShared(AllocatorControl alloc, long size, Drop drop, Cleaner cleaner) { var segment = createSegment(size).share(); if (cleaner != null) { segment = segment.registerCleaner(cleaner); } - return new MemSegBuf(segment, convert(drop), alloc); + return new MemSegBuffer(segment, convert(drop), alloc); } protected abstract MemorySegment createSegment(long size); @Override - public Drop drop() { - return convert(MemSegBuf.SEGMENT_CLOSE); + public Drop drop() { + return convert(MemSegBuffer.SEGMENT_CLOSE); } @Override - public Object unwrapRecoverableMemory(Buf buf) { - var b = (MemSegBuf) buf; + public Object unwrapRecoverableMemory(Buffer buf) { + var b = (MemSegBuffer) buf; return b.recoverableMemory(); } @Override - public Buf recoverMemory(Object recoverableMemory, Drop drop) { + public Buffer recoverMemory(Object recoverableMemory, Drop drop) { var recovery = (RecoverableMemory) recoverableMemory; return recovery.recover(convert(drop)); } diff --git a/src/main/java/io/netty/buffer/api/memseg/BifurcatedDrop.java b/src/main/java/io/netty/buffer/api/memseg/BifurcatedDrop.java index 91629d2..4a72f07 100644 --- a/src/main/java/io/netty/buffer/api/memseg/BifurcatedDrop.java +++ b/src/main/java/io/netty/buffer/api/memseg/BifurcatedDrop.java @@ -20,7 +20,7 @@ import io.netty.buffer.api.Drop; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; -class BifurcatedDrop implements Drop { +class BifurcatedDrop implements Drop { private static final VarHandle COUNT; static { try { @@ -30,12 +30,12 @@ class BifurcatedDrop implements Drop { } } - private final MemSegBuf originalBuf; - private final Drop delegate; + private final MemSegBuffer originalBuf; + private final Drop delegate; @SuppressWarnings("FieldMayBeFinal") private volatile int count; - BifurcatedDrop(MemSegBuf originalBuf, Drop delegate) { + BifurcatedDrop(MemSegBuffer originalBuf, Drop delegate) { this.originalBuf = originalBuf; this.delegate = delegate; count = 2; // These are created by buffer bifurcation, so we initially have 2 references to this drop. @@ -50,7 +50,7 @@ class BifurcatedDrop implements Drop { } @Override - public void drop(MemSegBuf buf) { + public void drop(MemSegBuffer buf) { int c; int n; do { @@ -66,11 +66,11 @@ class BifurcatedDrop implements Drop { } @Override - public void attach(MemSegBuf obj) { + public void attach(MemSegBuffer obj) { delegate.attach(obj); } - Drop unwrap() { + Drop unwrap() { return delegate; } diff --git a/src/main/java/io/netty/buffer/api/memseg/HeapMemorySegmentManager.java b/src/main/java/io/netty/buffer/api/memseg/HeapMemorySegmentManager.java index 71d32f0..01ec996 100644 --- a/src/main/java/io/netty/buffer/api/memseg/HeapMemorySegmentManager.java +++ b/src/main/java/io/netty/buffer/api/memseg/HeapMemorySegmentManager.java @@ -15,7 +15,7 @@ */ package io.netty.buffer.api.memseg; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.Buffer; import io.netty.buffer.api.Drop; import jdk.incubator.foreign.MemorySegment; @@ -31,13 +31,13 @@ public class HeapMemorySegmentManager extends AbstractMemorySegmentManager { } @Override - public Drop drop() { + public Drop drop() { return convert(buf -> buf.makeInaccessible()); } @SuppressWarnings({ "unchecked", "UnnecessaryLocalVariable" }) - private static Drop convert(Drop drop) { + private static Drop convert(Drop drop) { Drop tmp = drop; - return (Drop) tmp; + return (Drop) tmp; } } diff --git a/src/main/java/io/netty/buffer/api/memseg/MemSegBuf.java b/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java similarity index 91% rename from src/main/java/io/netty/buffer/api/memseg/MemSegBuf.java rename to src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java index fc8de9e..91cb069 100644 --- a/src/main/java/io/netty/buffer/api/memseg/MemSegBuf.java +++ b/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java @@ -15,9 +15,9 @@ */ package io.netty.buffer.api.memseg; -import io.netty.buffer.api.Allocator; +import io.netty.buffer.api.BufferAllocator; import io.netty.buffer.api.AllocatorControl; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.Buffer; import io.netty.buffer.api.ByteCursor; import io.netty.buffer.api.ComponentProcessor.ReadableComponent; import io.netty.buffer.api.ComponentProcessor.ReadableComponentProcessor; @@ -46,9 +46,9 @@ import static jdk.incubator.foreign.MemoryAccess.setIntAtOffset; import static jdk.incubator.foreign.MemoryAccess.setLongAtOffset; import static jdk.incubator.foreign.MemoryAccess.setShortAtOffset; -class MemSegBuf extends RcSupport implements Buf, ReadableComponent, WritableComponent { +class MemSegBuffer extends RcSupport implements Buffer, ReadableComponent, WritableComponent { private static final MemorySegment CLOSED_SEGMENT; - static final Drop SEGMENT_CLOSE; + static final Drop SEGMENT_CLOSE; static { CLOSED_SEGMENT = MemorySegment.ofArray(new byte[0]); @@ -68,11 +68,11 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon private int roff; private int woff; - MemSegBuf(MemorySegment segmet, Drop drop, AllocatorControl alloc) { + MemSegBuffer(MemorySegment segmet, Drop drop, AllocatorControl alloc) { this(segmet, drop, alloc, true); } - private MemSegBuf(MemorySegment segment, Drop drop, AllocatorControl alloc, boolean isSendable) { + private MemSegBuffer(MemorySegment segment, Drop drop, AllocatorControl alloc, boolean isSendable) { super(drop); this.alloc = alloc; seg = segment; @@ -83,11 +83,11 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon @Override public String toString() { - return "Buf[roff:" + roff + ", woff:" + woff + ", cap:" + seg.byteSize() + ']'; + return "Buffer[roff:" + roff + ", woff:" + woff + ", cap:" + seg.byteSize() + ']'; } @Override - public Buf order(ByteOrder order) { + public Buffer order(ByteOrder order) { this.order = order; return this; } @@ -108,7 +108,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public MemSegBuf readerOffset(int index) { + public MemSegBuffer readerOffset(int index) { checkRead(index, 0); roff = index; return this; @@ -120,14 +120,14 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public MemSegBuf writerOffset(int index) { + public MemSegBuffer writerOffset(int index) { checkWrite(index, 0); woff = index; return this; } @Override - public Buf fill(byte value) { + public Buffer fill(byte value) { checkWrite(0, capacity()); seg.fill(value); return this; @@ -213,7 +213,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf readOnly(boolean readOnly) { + public Buffer readOnly(boolean readOnly) { wseg = readOnly? CLOSED_SEGMENT : seg; return this; } @@ -224,18 +224,18 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf slice(int offset, int length) { + public Buffer slice(int offset, int length) { if (length < 0) { throw new IllegalArgumentException("Length cannot be negative: " + length + '.'); } var slice = seg.asSlice(offset, length); acquire(); - Drop drop = b -> { + Drop drop = b -> { close(); b.makeInaccessible(); }; var sendable = false; // Sending implies ownership change, which we can't do for slices. - return new MemSegBuf(slice, drop, alloc, sendable) + return new MemSegBuffer(slice, drop, alloc, sendable) .writerOffset(length) .order(order()) .readOnly(readOnly()); @@ -273,9 +273,9 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public void copyInto(int srcPos, Buf dest, int destPos, int length) { - if (dest instanceof MemSegBuf) { - var memSegBuf = (MemSegBuf) dest; + public void copyInto(int srcPos, Buffer dest, int destPos, int length) { + if (dest instanceof MemSegBuffer) { + var memSegBuf = (MemSegBuffer) dest; memSegBuf.checkWrite(destPos, length); copyInto(srcPos, memSegBuf.seg, destPos, length); return; @@ -456,7 +456,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon // Allocate a bigger buffer. long newSize = capacity() + size - (long) writableBytes(); - Allocator.checkSize(newSize); + BufferAllocator.checkSize(newSize); RecoverableMemory recoverableMemory = (RecoverableMemory) alloc.allocateUntethered(this, (int) newSize); var newSegment = recoverableMemory.segment; @@ -484,7 +484,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf bifurcate() { + public Buffer bifurcate() { if (!isOwned()) { throw new IllegalStateException("Cannot bifurcate a buffer that is not owned."); } @@ -496,11 +496,11 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon if (drop instanceof BifurcatedDrop) { ((BifurcatedDrop) drop).increment(); } else { - drop = new BifurcatedDrop(new MemSegBuf(seg, drop, alloc), drop); + drop = new BifurcatedDrop(new MemSegBuffer(seg, drop, alloc), drop); unsafeSetDrop(drop); } var bifurcatedSeg = seg.asSlice(0, woff); - var bifurcatedBuf = new MemSegBuf(bifurcatedSeg, drop, alloc); + var bifurcatedBuf = new MemSegBuffer(bifurcatedSeg, drop, alloc); bifurcatedBuf.woff = woff; bifurcatedBuf.roff = roff; bifurcatedBuf.order(order); @@ -591,7 +591,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeByte(byte value) { + public Buffer writeByte(byte value) { try { setByteAtOffset(wseg, woff, value); woff += Byte.BYTES; @@ -602,7 +602,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setByte(int woff, byte value) { + public Buffer setByte(int woff, byte value) { try { setByteAtOffset(wseg, woff, value); return this; @@ -612,7 +612,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeUnsignedByte(int value) { + public Buffer writeUnsignedByte(int value) { try { setByteAtOffset(wseg, woff, (byte) (value & 0xFF)); woff += Byte.BYTES; @@ -623,7 +623,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setUnsignedByte(int woff, int value) { + public Buffer setUnsignedByte(int woff, int value) { try { setByteAtOffset(wseg, woff, (byte) (value & 0xFF)); return this; @@ -647,7 +647,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeChar(char value) { + public Buffer writeChar(char value) { try { setCharAtOffset(wseg, woff, order, value); woff += 2; @@ -658,7 +658,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setChar(int woff, char value) { + public Buffer setChar(int woff, char value) { try { setCharAtOffset(wseg, woff, order, value); return this; @@ -696,7 +696,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeShort(short value) { + public Buffer writeShort(short value) { try { setShortAtOffset(wseg, woff, order, value); woff += Short.BYTES; @@ -707,7 +707,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setShort(int woff, short value) { + public Buffer setShort(int woff, short value) { try { setShortAtOffset(wseg, woff, order, value); return this; @@ -717,7 +717,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeUnsignedShort(int value) { + public Buffer writeUnsignedShort(int value) { try { setShortAtOffset(wseg, woff, order, (short) (value & 0xFFFF)); woff += Short.BYTES; @@ -728,7 +728,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setUnsignedShort(int woff, int value) { + public Buffer setUnsignedShort(int woff, int value) { try { setShortAtOffset(wseg, woff, order, (short) (value & 0xFFFF)); return this; @@ -790,7 +790,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeMedium(int value) { + public Buffer writeMedium(int value) { checkWrite(woff, 3); if (order == ByteOrder.BIG_ENDIAN) { setByteAtOffset(wseg, woff, (byte) (value >> 16)); @@ -806,7 +806,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setMedium(int woff, int value) { + public Buffer setMedium(int woff, int value) { checkWrite(woff, 3); if (order == ByteOrder.BIG_ENDIAN) { setByteAtOffset(wseg, woff, (byte) (value >> 16)); @@ -821,7 +821,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeUnsignedMedium(int value) { + public Buffer writeUnsignedMedium(int value) { checkWrite(woff, 3); if (order == ByteOrder.BIG_ENDIAN) { setByteAtOffset(wseg, woff, (byte) (value >> 16)); @@ -837,7 +837,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setUnsignedMedium(int woff, int value) { + public Buffer setUnsignedMedium(int woff, int value) { checkWrite(woff, 3); if (order == ByteOrder.BIG_ENDIAN) { setByteAtOffset(wseg, woff, (byte) (value >> 16)); @@ -880,7 +880,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeInt(int value) { + public Buffer writeInt(int value) { try { setIntAtOffset(wseg, woff, order, value); woff += Integer.BYTES; @@ -891,7 +891,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setInt(int woff, int value) { + public Buffer setInt(int woff, int value) { try { setIntAtOffset(wseg, woff, order, value); return this; @@ -901,7 +901,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeUnsignedInt(long value) { + public Buffer writeUnsignedInt(long value) { try { setIntAtOffset(wseg, woff, order, (int) (value & 0xFFFFFFFFL)); woff += Integer.BYTES; @@ -912,7 +912,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setUnsignedInt(int woff, long value) { + public Buffer setUnsignedInt(int woff, long value) { try { setIntAtOffset(wseg, woff, order, (int) (value & 0xFFFFFFFFL)); return this; @@ -936,7 +936,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeFloat(float value) { + public Buffer writeFloat(float value) { try { setFloatAtOffset(wseg, woff, order, value); woff += Float.BYTES; @@ -947,7 +947,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setFloat(int woff, float value) { + public Buffer setFloat(int woff, float value) { try { setFloatAtOffset(wseg, woff, order, value); return this; @@ -971,7 +971,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeLong(long value) { + public Buffer writeLong(long value) { try { setLongAtOffset(wseg, woff, order, value); woff += Long.BYTES; @@ -982,7 +982,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setLong(int woff, long value) { + public Buffer setLong(int woff, long value) { try { setLongAtOffset(wseg, woff, order, value); return this; @@ -1006,7 +1006,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf writeDouble(double value) { + public Buffer writeDouble(double value) { try { setDoubleAtOffset(wseg, woff, order, value); woff += Double.BYTES; @@ -1017,7 +1017,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon } @Override - public Buf setDouble(int woff, double value) { + public Buffer setDouble(int woff, double value) { try { setDoubleAtOffset(wseg, woff, order, value); return this; @@ -1028,7 +1028,7 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon // @Override - protected Owned prepareSend() { + protected Owned prepareSend() { var order = this.order; var roff = this.roff; var woff = this.woff; @@ -1036,10 +1036,10 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon boolean isConfined = seg.ownerThread() == null; MemorySegment transferSegment = isConfined? seg : seg.share(); makeInaccessible(); - return new Owned() { + return new Owned() { @Override - public MemSegBuf transferOwnership(Drop drop) { - MemSegBuf copy = new MemSegBuf(transferSegment, drop, alloc); + public MemSegBuffer transferOwnership(Drop drop) { + MemSegBuffer copy = new MemSegBuffer(transferSegment, drop, alloc); copy.order = order; copy.roff = roff; copy.woff = woff; @@ -1136,8 +1136,8 @@ class MemSegBuf extends RcSupport implements Buf, ReadableCompon this.alloc = alloc; } - Buf recover(Drop drop) { - return new MemSegBuf(segment, drop, alloc); + Buffer recover(Drop drop) { + return new MemSegBuffer(segment, drop, alloc); } } } diff --git a/src/main/java/io/netty/buffer/api/memseg/package-info.java b/src/main/java/io/netty/buffer/api/memseg/package-info.java index 429d64a..4940ee0 100644 --- a/src/main/java/io/netty/buffer/api/memseg/package-info.java +++ b/src/main/java/io/netty/buffer/api/memseg/package-info.java @@ -15,6 +15,6 @@ */ /** - * Experimental {@code Buf} implementation, based on the MemorySegment API from OpenJDK Panama Foreign. + * Experimental {@code Buffer} implementation, based on the MemorySegment API from OpenJDK Panama Foreign. */ package io.netty.buffer.api.memseg; diff --git a/src/main/java/io/netty/buffer/api/package-info.java b/src/main/java/io/netty/buffer/api/package-info.java index 7ef007b..e38b44c 100644 --- a/src/main/java/io/netty/buffer/api/package-info.java +++ b/src/main/java/io/netty/buffer/api/package-info.java @@ -15,6 +15,6 @@ */ /** - * Incubating {@code Buf} API, as a proposed alternative to {@code ByteBuf}. + * Incubating {@code Buffer} API, as a proposed alternative to {@code ByteBuf}. */ package io.netty.buffer.api; diff --git a/src/test/java/io/netty/buffer/api/BufRefTest.java b/src/test/java/io/netty/buffer/api/BufferRefTest.java similarity index 70% rename from src/test/java/io/netty/buffer/api/BufRefTest.java rename to src/test/java/io/netty/buffer/api/BufferRefTest.java index 0bc8d0a..7a3b271 100644 --- a/src/test/java/io/netty/buffer/api/BufRefTest.java +++ b/src/test/java/io/netty/buffer/api/BufferRefTest.java @@ -20,13 +20,13 @@ import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; -class BufRefTest { +class BufferRefTest { @Test public void closingBufRefMustCloseOwnedBuf() { - try (Allocator allocator = Allocator.heap()) { - BufRef ref; - try (Buf b = allocator.allocate(8)) { - ref = new BufRef(b); + try (BufferAllocator allocator = BufferAllocator.heap()) { + BufferRef ref; + try (Buffer b = allocator.allocate(8)) { + ref = new BufferRef(b); } ref.contents().writeInt(42); assertThat(ref.contents().readInt()).isEqualTo(42); @@ -37,9 +37,9 @@ class BufRefTest { @Test public void closingBufRefMustCloseOwnedBufFromSend() { - try (Allocator allocator = Allocator.heap(); - Buf buf = allocator.allocate(8)) { - BufRef ref = new BufRef(buf.send()); + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer buf = allocator.allocate(8)) { + BufferRef ref = new BufferRef(buf.send()); ref.contents().writeInt(42); assertThat(ref.contents().readInt()).isEqualTo(42); ref.close(); @@ -49,17 +49,17 @@ class BufRefTest { @Test public void mustCloseOwnedBufferWhenReplaced() { - try (Allocator allocator = Allocator.heap()) { - Buf orig; - BufRef ref; - try (Buf buf = allocator.allocate(8)) { - ref = new BufRef(orig = buf); + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer orig; + BufferRef ref; + try (Buffer buf = allocator.allocate(8)) { + ref = new BufferRef(orig = buf); } orig.writeInt(42); assertThat(ref.contents().readInt()).isEqualTo(42); - try (Buf buf = allocator.allocate(8)) { + try (Buffer buf = allocator.allocate(8)) { ref.replace(buf); // Pass replacement directly. } @@ -73,17 +73,17 @@ class BufRefTest { @Test public void mustCloseOwnedBufferWhenReplacedFromSend() { - try (Allocator allocator = Allocator.heap()) { - Buf orig; - BufRef ref; - try (Buf buf = allocator.allocate(8)) { - ref = new BufRef(orig = buf); + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer orig; + BufferRef ref; + try (Buffer buf = allocator.allocate(8)) { + ref = new BufferRef(orig = buf); } orig.writeInt(42); assertThat(ref.contents().readInt()).isEqualTo(42); - try (Buf buf = allocator.allocate(8)) { + try (Buffer buf = allocator.allocate(8)) { ref.replace(buf.send()); // Pass replacement via send(). } @@ -97,12 +97,12 @@ class BufRefTest { @Test public void sendingRefMustSendBuffer() { - try (Allocator allocator = Allocator.heap(); - BufRef refA = new BufRef(allocator.allocate(8).send())) { + try (BufferAllocator allocator = BufferAllocator.heap(); + BufferRef refA = new BufferRef(allocator.allocate(8).send())) { refA.contents().writeInt(42); - Send send = refA.send(); + Send send = refA.send(); assertThrows(IllegalStateException.class, () -> refA.contents().readInt()); - try (BufRef refB = send.receive()) { + try (BufferRef refB = send.receive()) { assertThat(refB.contents().readInt()).isEqualTo(42); } } diff --git a/src/test/java/io/netty/buffer/api/BufTest.java b/src/test/java/io/netty/buffer/api/BufferTest.java similarity index 79% rename from src/test/java/io/netty/buffer/api/BufTest.java rename to src/test/java/io/netty/buffer/api/BufferTest.java index a6dd3ea..0201fea 100644 --- a/src/test/java/io/netty/buffer/api/BufTest.java +++ b/src/test/java/io/netty/buffer/api/BufferTest.java @@ -58,7 +58,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -public class BufTest { +public class BufferTest { private static volatile Fixture[] fixtures; private static ExecutorService executor; @@ -72,10 +72,10 @@ public class BufTest { static List initialAllocators() { return List.of( - new Fixture("heap", Allocator::heap, HEAP), - new Fixture("direct", Allocator::direct, DIRECT, CLEANER), - new Fixture("pooledHeap", Allocator::pooledHeap, POOLED, HEAP), - new Fixture("pooledDirect", Allocator::pooledDirect, POOLED, DIRECT, CLEANER)); + new Fixture("heap", BufferAllocator::heap, HEAP), + new Fixture("direct", BufferAllocator::direct, DIRECT, CLEANER), + new Fixture("pooledHeap", BufferAllocator::pooledHeap, POOLED, HEAP), + new Fixture("pooledDirect", BufferAllocator::pooledDirect, POOLED, DIRECT, CLEANER)); } static Stream nonSliceAllocators() { @@ -117,12 +117,12 @@ public class BufTest { var a = first.get(); var b = second.get(); builder.add(new Fixture("compose(" + first + ", " + second + ')', () -> { - return new Allocator() { + return new BufferAllocator() { @Override - public Buf allocate(int size) { + public Buffer allocate(int size) { int half = size / 2; - try (Buf firstHalf = a.allocate(half); - Buf secondHalf = b.allocate(size - half)) { + try (Buffer firstHalf = a.allocate(half); + Buffer secondHalf = b.allocate(size - half)) { return a.compose(firstHalf, secondHalf); } } @@ -139,14 +139,14 @@ public class BufTest { // Also add a 3-way composite buffer. builder.add(new Fixture("compose(heap,heap,heap)", () -> { - return new Allocator() { - final Allocator alloc = Allocator.heap(); + return new BufferAllocator() { + final BufferAllocator alloc = BufferAllocator.heap(); @Override - public Buf allocate(int size) { + public Buffer allocate(int size) { int part = size / 3; - try (Buf a = alloc.allocate(part); - Buf b = alloc.allocate(part); - Buf c = alloc.allocate(size - part * 2)) { + try (Buffer a = alloc.allocate(part); + Buffer b = alloc.allocate(part); + Buffer c = alloc.allocate(size - part * 2)) { return alloc.compose(a, b, c); } } @@ -161,9 +161,9 @@ public class BufTest { for (Fixture fixture : initFixtures) { builder.add(new Fixture(fixture + ".ensureWritable", () -> { var allocator = fixture.createAllocator(); - return new Allocator() { + return new BufferAllocator() { @Override - public Buf allocate(int size) { + public Buffer allocate(int size) { if (size < 2) { return allocator.allocate(size); } @@ -180,9 +180,9 @@ public class BufTest { }, fixture.getProperties())); builder.add(new Fixture(fixture + ".compose.ensureWritable", () -> { var allocator = fixture.createAllocator(); - return new Allocator() { + return new BufferAllocator() { @Override - public Buf allocate(int size) { + public Buffer allocate(int size) { if (size < 2) { return allocator.allocate(size); } @@ -200,9 +200,9 @@ public class BufTest { } var stream = builder.build(); - return stream.flatMap(BufTest::injectBifurcations) - .flatMap(BufTest::injectSlices) - .flatMap(BufTest::injectReadOnlyToggling); + return stream.flatMap(BufferTest::injectBifurcations) + .flatMap(BufferTest::injectSlices) + .flatMap(BufferTest::injectReadOnlyToggling); } private static Stream injectBifurcations(Fixture f) { @@ -210,10 +210,10 @@ public class BufTest { builder.add(f); builder.add(new Fixture(f + ".bifurcate", () -> { var allocatorBase = f.get(); - return new Allocator() { + return new BufferAllocator() { @Override - public Buf allocate(int size) { - try (Buf buf = allocatorBase.allocate(size + 1)) { + public Buffer allocate(int size) { + try (Buffer buf = allocatorBase.allocate(size + 1)) { buf.writerOffset(size); return buf.bifurcate().writerOffset(0); } @@ -234,10 +234,10 @@ public class BufTest { var props = concat(f.getProperties(), Properties.SLICE); builder.add(new Fixture(f + ".slice(0, capacity())", () -> { var allocatorBase = f.get(); - return new Allocator() { + return new BufferAllocator() { @Override - public Buf allocate(int size) { - try (Buf base = allocatorBase.allocate(size)) { + public Buffer allocate(int size) { + try (Buffer base = allocatorBase.allocate(size)) { return base.slice(0, base.capacity()).writerOffset(0); } } @@ -250,10 +250,10 @@ public class BufTest { }, props)); builder.add(new Fixture(f + ".slice(1, capacity() - 2)", () -> { var allocatorBase = f.get(); - return new Allocator() { + return new BufferAllocator() { @Override - public Buf allocate(int size) { - try (Buf base = allocatorBase.allocate(size + 2)) { + public Buffer allocate(int size) { + try (Buffer base = allocatorBase.allocate(size + 2)) { return base.slice(1, size).writerOffset(0); } } @@ -272,9 +272,9 @@ public class BufTest { builder.add(f); builder.add(new Fixture(f + ".readOnly(true/false)", () -> { var allocatorBase = f.get(); - return new Allocator() { + return new BufferAllocator() { @Override - public Buf allocate(int size) { + public Buffer allocate(int size) { return allocatorBase.allocate(size).readOnly(true).readOnly(false); } @@ -306,11 +306,11 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void allocateAndAccessingBuffer(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.writeByte((byte) 1); buf.writeByte((byte) 2); - try (Buf inner = buf.acquire()) { + try (Buffer inner = buf.acquire()) { inner.writeByte((byte) 3); inner.writeByte((byte) 4); inner.writeByte((byte) 5); @@ -341,7 +341,7 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void acquireOnClosedBufferMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { + try (BufferAllocator allocator = fixture.createAllocator()) { var buf = allocator.allocate(8); buf.close(); assertThrows(IllegalStateException.class, buf::acquire); @@ -351,15 +351,15 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") void allocateAndSendToThread(Fixture fixture) throws Exception { - try (Allocator allocator = fixture.createAllocator()) { - ArrayBlockingQueue> queue = new ArrayBlockingQueue<>(10); + try (BufferAllocator allocator = fixture.createAllocator()) { + ArrayBlockingQueue> queue = new ArrayBlockingQueue<>(10); Future future = executor.submit(() -> { - try (Buf byteBuf = queue.take().receive()) { + try (Buffer byteBuf = queue.take().receive()) { return byteBuf.readByte(); } }); - try (Buf buf = allocator.allocate(8)) { + try (Buffer buf = allocator.allocate(8)) { buf.writeByte((byte) 42); assertTrue(queue.offer(buf.send())); } @@ -371,15 +371,15 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") void allocateAndSendToThreadViaSyncQueue(Fixture fixture) throws Exception { - SynchronousQueue> queue = new SynchronousQueue<>(); + SynchronousQueue> queue = new SynchronousQueue<>(); Future future = executor.submit(() -> { - try (Buf byteBuf = queue.take().receive()) { + try (Buffer byteBuf = queue.take().receive()) { return byteBuf.readByte(); } }); - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThat(buf.writeByte((byte) 42)).isSameAs(buf); queue.put(buf.send()); } @@ -390,9 +390,9 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") void sendMustThrowWhenBufIsAcquired(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { - try (Buf ignored = buf.acquire()) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + try (Buffer ignored = buf.acquire()) { assertFalse(buf.isOwned()); assertThrows(IllegalStateException.class, buf::send); } @@ -405,29 +405,29 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void originalBufferMustNotBeAccessibleAfterSend(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf orig = allocator.allocate(24)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer orig = allocator.allocate(24)) { orig.writeLong(42); var send = orig.send(); verifyInaccessible(orig); - try (Buf receive = send.receive()) { + try (Buffer receive = send.receive()) { assertEquals(42, receive.readInt()); } } } - private static void verifyInaccessible(Buf buf) { + private static void verifyInaccessible(Buffer buf) { verifyReadInaccessible(buf); verifyWriteInaccessible(buf); - try (Allocator allocator = Allocator.heap(); - Buf target = allocator.allocate(24)) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer target = allocator.allocate(24)) { assertThrows(IllegalStateException.class, () -> buf.copyInto(0, target, 0, 1)); assertThrows(IllegalStateException.class, () -> buf.copyInto(0, new byte[1], 0, 1)); assertThrows(IllegalStateException.class, () -> buf.copyInto(0, ByteBuffer.allocate(1), 0, 1)); - if (Allocator.isComposite(buf)) { - assertThrows(IllegalStateException.class, () -> Allocator.extend(buf, target)); + if (BufferAllocator.isComposite(buf)) { + assertThrows(IllegalStateException.class, () -> BufferAllocator.extend(buf, target)); } } @@ -441,7 +441,7 @@ public class BufTest { assertThrows(IllegalStateException.class, () -> buf.openReverseCursor(0, 0)); } - private static void verifyReadInaccessible(Buf buf) { + private static void verifyReadInaccessible(Buffer buf) { assertThrows(IllegalStateException.class, () -> buf.readByte()); assertThrows(IllegalStateException.class, () -> buf.readUnsignedByte()); assertThrows(IllegalStateException.class, () -> buf.readChar()); @@ -469,7 +469,7 @@ public class BufTest { assertThrows(IllegalStateException.class, () -> buf.getDouble(0)); } - private static void verifyWriteInaccessible(Buf buf) { + private static void verifyWriteInaccessible(Buffer buf) { assertThrows(IllegalStateException.class, () -> buf.writeByte((byte) 32)); assertThrows(IllegalStateException.class, () -> buf.writeUnsignedByte(32)); assertThrows(IllegalStateException.class, () -> buf.writeChar('3')); @@ -498,8 +498,8 @@ public class BufTest { assertThrows(IllegalStateException.class, () -> buf.ensureWritable(1)); assertThrows(IllegalStateException.class, () -> buf.fill((byte) 0)); - try (Allocator allocator = Allocator.heap(); - Buf source = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer source = allocator.allocate(8)) { assertThrows(IllegalStateException.class, () -> source.copyInto(0, buf, 0, 1)); } } @@ -507,8 +507,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void cannotSendMoreThanOnce(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { var send = buf.send(); var exc = assertThrows(IllegalStateException.class, () -> buf.send()); send.receive().close(); @@ -519,8 +519,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void bufferShouldNotBeAccessibleAfterClose(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { - Buf buf = allocator.allocate(24); + try (BufferAllocator allocator = fixture.createAllocator()) { + Buffer buf = allocator.allocate(24); buf.writeLong(42); buf.close(); verifyInaccessible(buf); @@ -530,8 +530,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void bufferMustNotBeThreadConfined(Fixture fixture) throws Exception { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.writeInt(42); Future fut = executor.submit(() -> buf.readInt()); assertEquals(42, fut.get()); @@ -546,7 +546,7 @@ public class BufTest { @ParameterizedTest @MethodSource("initialAllocators") void mustThrowWhenAllocatingZeroSizedBuffer(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { + try (BufferAllocator allocator = fixture.createAllocator()) { assertThrows(IllegalArgumentException.class, () -> allocator.allocate(0)); } } @@ -554,7 +554,7 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void mustThrowWhenAllocatingNegativeSizedBuffer(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { + try (BufferAllocator allocator = fixture.createAllocator()) { assertThrows(IllegalArgumentException.class, () -> allocator.allocate(-1)); } } @@ -562,8 +562,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void setReaderOffsetMustThrowOnNegativeIndex(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readerOffset(-1)); } } @@ -571,8 +571,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void setReaderOffsetMustThrowOnOversizedIndex(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readerOffset(1)); buf.writeLong(0); assertThrows(IndexOutOfBoundsException.class, () -> buf.readerOffset(9)); @@ -585,8 +585,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void setReaderOffsetMustNotThrowWithinBounds(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThat(buf.readerOffset(0)).isSameAs(buf); buf.writeLong(0); assertThat(buf.readerOffset(7)).isSameAs(buf); @@ -597,10 +597,10 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void capacityMustBeAllocatedSize(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(8, buf.capacity()); - try (Buf b = allocator.allocate(13)) { + try (Buffer b = allocator.allocate(13)) { assertEquals(13, b.capacity()); } } @@ -609,8 +609,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void fill(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(16)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(16)) { assertThat(buf.fill((byte) 0xA5)).isSameAs(buf); buf.writerOffset(16); assertEquals(0xA5A5A5A5_A5A5A5A5L, buf.readLong()); @@ -621,8 +621,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void readerWriterOffsetUpdates(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(22)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(22)) { assertEquals(0, buf.writerOffset()); assertThat(buf.writerOffset(1)).isSameAs(buf); assertEquals(1, buf.writerOffset()); @@ -655,8 +655,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void readAndWriteBoundsChecksWithIndexUpdates(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.writeLong(0); buf.readLong(); // Fine. @@ -674,8 +674,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void resetMustSetReaderAndWriterOffsetsToTheirInitialPositions(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.writeInt(0).readShort(); buf.reset(); assertEquals(0, buf.readerOffset()); @@ -686,14 +686,14 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithoutOffsetAndSizeMustReturnReadableRegion(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { for (byte b : new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }) { buf.writeByte(b); } assertEquals(0x01, buf.readByte()); buf.writerOffset(buf.writerOffset() - 1); - try (Buf slice = buf.slice()) { + try (Buffer slice = buf.slice()) { assertThat(toByteArray(slice)).containsExactly(0x02, 0x03, 0x04, 0x05, 0x06, 0x07); assertEquals(0, slice.readerOffset()); assertEquals(6, slice.readableBytes()); @@ -713,14 +713,14 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithOffsetAndSizeMustReturnGivenRegion(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { for (byte b : new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }) { buf.writeByte(b); } buf.readerOffset(3); // Reader and writer offsets must be ignored. buf.writerOffset(6); - try (Buf slice = buf.slice(1, 6)) { + try (Buffer slice = buf.slice(1, 6)) { assertThat(toByteArray(slice)).containsExactly(0x02, 0x03, 0x04, 0x05, 0x06, 0x07); assertEquals(0, slice.readerOffset()); assertEquals(6, slice.readableBytes()); @@ -740,10 +740,10 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithoutOffsetAndSizeWillIncreaseReferenceCount(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int borrows = buf.countBorrows(); - try (Buf ignored = buf.slice()) { + try (Buffer ignored = buf.slice()) { assertFalse(buf.isOwned()); assertThrows(IllegalStateException.class, buf::send); } @@ -754,10 +754,10 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithOffsetAndSizeWillIncreaseReferenceCount(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int borrows = buf.countBorrows(); - try (Buf ignored = buf.slice(0, 8)) { + try (Buffer ignored = buf.slice(0, 8)) { assertFalse(buf.isOwned()); assertThrows(IllegalStateException.class, buf::send); } @@ -768,15 +768,15 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithoutOffsetAndSizeHasSameEndianAsParent(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); buf.writeLong(0x0102030405060708L); - try (Buf slice = buf.slice()) { + try (Buffer slice = buf.slice()) { assertEquals(0x0102030405060708L, slice.readLong()); } buf.order(LITTLE_ENDIAN); - try (Buf slice = buf.slice()) { + try (Buffer slice = buf.slice()) { assertEquals(0x0807060504030201L, slice.readLong()); } } @@ -785,15 +785,15 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithOffsetAndSizeHasSameEndianAsParent(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); buf.writeLong(0x0102030405060708L); - try (Buf slice = buf.slice(0, 8)) { + try (Buffer slice = buf.slice(0, 8)) { assertEquals(0x0102030405060708L, slice.readLong()); } buf.order(LITTLE_ENDIAN); - try (Buf slice = buf.slice(0, 8)) { + try (Buffer slice = buf.slice(0, 8)) { assertEquals(0x0807060504030201L, slice.readLong()); } } @@ -802,9 +802,9 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") void sendOnSliceWithoutOffsetAndSizeMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { - try (Buf slice = buf.slice()) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + try (Buffer slice = buf.slice()) { assertFalse(buf.isOwned()); assertThrows(IllegalStateException.class, slice::send); } @@ -817,9 +817,9 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") void sendOnSliceWithOffsetAndSizeMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { - try (Buf slice = buf.slice(0, 8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + try (Buffer slice = buf.slice(0, 8)) { assertFalse(buf.isOwned()); assertThrows(IllegalStateException.class, slice::send); } @@ -831,8 +831,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithNegativeOffsetMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int borrows = buf.countBorrows(); assertThrows(IndexOutOfBoundsException.class, () -> buf.slice(-1, 1)); // Verify that the slice is closed properly afterwards. @@ -843,8 +843,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithNegativeSizeMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int borrows = buf.countBorrows(); assertThrows(IllegalArgumentException.class, () -> buf.slice(0, -1)); // Verify that the slice is closed properly afterwards. @@ -855,8 +855,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithSizeGreaterThanCapacityMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int borrows = buf.countBorrows(); assertThrows(IndexOutOfBoundsException.class, () -> buf.slice(0, 9)); buf.slice(0, 8).close(); // This is still fine. @@ -869,8 +869,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void sliceWithZeroSizeMustBeAllowed(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int borrows = buf.countBorrows(); buf.slice(0, 0).close(); // This is fine. // Verify that the slice is closed properly afterwards. @@ -881,16 +881,16 @@ public class BufTest { @ParameterizedTest @MethodSource("nonCompositeAllocators") public void acquireComposingAndSlicingMustIncrementBorrows(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int borrows = buf.countBorrows(); - try (Buf ignored = buf.acquire()) { + try (Buffer ignored = buf.acquire()) { assertEquals(borrows + 1, buf.countBorrows()); - try (Buf slice = buf.slice()) { + try (Buffer slice = buf.slice()) { assertEquals(0, slice.capacity()); // We haven't written anything, so the slice is empty. int sliceBorrows = slice.countBorrows(); assertEquals(borrows + 2, buf.countBorrows()); - try (Buf ignored1 = allocator.compose(buf, slice)) { + try (Buffer ignored1 = allocator.compose(buf, slice)) { assertEquals(borrows + 3, buf.countBorrows()); // Note: Slice is empty; not acquired by the composite buffer. assertEquals(sliceBorrows, slice.countBorrows()); @@ -907,8 +907,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void copyIntoByteArray(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN).writeLong(0x0102030405060708L); byte[] array = new byte[8]; buf.copyInto(0, array, 0, array.length); @@ -937,8 +937,8 @@ public class BufTest { } private static void testCopyIntoByteBuffer(Fixture fixture, Function bbAlloc) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN).writeLong(0x0102030405060708L); ByteBuffer buffer = bbAlloc.apply(8); buf.copyInto(0, buffer, 0, buffer.capacity()); @@ -992,36 +992,42 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void copyIntoOnHeapBuf(Fixture fixture) { - testCopyIntoBuf(fixture, Allocator.heap()::allocate); + testCopyIntoBuf(fixture, BufferAllocator.heap()::allocate); } @ParameterizedTest @MethodSource("allocators") void copyIntoOffHeapBuf(Fixture fixture) { - testCopyIntoBuf(fixture, Allocator.direct()::allocate); + testCopyIntoBuf(fixture, BufferAllocator.direct()::allocate); } @ParameterizedTest @MethodSource("allocators") void copyIntoOnHeapBufSlice(Fixture fixture) { - try (Scope scope = new Scope()) { - testCopyIntoBuf(fixture, size -> scope.add(Allocator.heap().allocate(size)).writerOffset(size).slice()); + try (BufferAllocator allocator = BufferAllocator.heap(); + Scope scope = new Scope()) { + testCopyIntoBuf(fixture, size -> { + return scope.add(allocator.allocate(size)).writerOffset(size).slice(); + }); } } @ParameterizedTest @MethodSource("allocators") void copyIntoOffHeapBufSlice(Fixture fixture) { - try (Scope scope = new Scope()) { - testCopyIntoBuf(fixture, size -> scope.add(Allocator.direct().allocate(size)).writerOffset(size).slice()); + try (BufferAllocator allocator = BufferAllocator.direct(); + Scope scope = new Scope()) { + testCopyIntoBuf(fixture, size -> { + return scope.add(allocator.allocate(size)).writerOffset(size).slice(); + }); } } @ParameterizedTest @MethodSource("allocators") void copyIntoCompositeOnHeapOnHeapBuf(Fixture fixture) { - try (var a = Allocator.heap(); - var b = Allocator.heap()) { + try (var a = BufferAllocator.heap(); + var b = BufferAllocator.heap()) { testCopyIntoBuf(fixture, size -> { int first = size / 2; int second = size - first; @@ -1036,8 +1042,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void copyIntoCompositeOnHeapOffHeapBuf(Fixture fixture) { - try (var a = Allocator.heap(); - var b = Allocator.direct()) { + try (var a = BufferAllocator.heap(); + var b = BufferAllocator.direct()) { testCopyIntoBuf(fixture, size -> { int first = size / 2; int second = size - first; @@ -1052,8 +1058,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void copyIntoCompositeOffHeapOnHeapBuf(Fixture fixture) { - try (var a = Allocator.direct(); - var b = Allocator.heap()) { + try (var a = BufferAllocator.direct(); + var b = BufferAllocator.heap()) { testCopyIntoBuf(fixture, size -> { int first = size / 2; int second = size - first; @@ -1068,8 +1074,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void copyIntoCompositeOffHeapOffHeapBuf(Fixture fixture) { - try (var a = Allocator.direct(); - var b = Allocator.direct()) { + try (var a = BufferAllocator.direct(); + var b = BufferAllocator.direct()) { testCopyIntoBuf(fixture, size -> { int first = size / 2; int second = size - first; @@ -1084,8 +1090,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void copyIntoCompositeOnHeapOnHeapBufSlice(Fixture fixture) { - try (var a = Allocator.heap(); - var b = Allocator.heap(); + try (var a = BufferAllocator.heap(); + var b = BufferAllocator.heap(); var scope = new Scope()) { testCopyIntoBuf(fixture, size -> { int first = size / 2; @@ -1101,8 +1107,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void copyIntoCompositeOnHeapOffHeapBufSlice(Fixture fixture) { - try (var a = Allocator.heap(); - var b = Allocator.direct(); + try (var a = BufferAllocator.heap(); + var b = BufferAllocator.direct(); var scope = new Scope()) { testCopyIntoBuf(fixture, size -> { int first = size / 2; @@ -1118,8 +1124,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void copyIntoCompositeOffHeapOnHeapBufSlice(Fixture fixture) { - try (var a = Allocator.direct(); - var b = Allocator.heap(); + try (var a = BufferAllocator.direct(); + var b = BufferAllocator.heap(); var scope = new Scope()) { testCopyIntoBuf(fixture, size -> { int first = size / 2; @@ -1135,8 +1141,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void copyIntoCompositeOffHeapOffHeapBufSlice(Fixture fixture) { - try (var a = Allocator.direct(); - var b = Allocator.direct(); + try (var a = BufferAllocator.direct(); + var b = BufferAllocator.direct(); var scope = new Scope()) { testCopyIntoBuf(fixture, size -> { int first = size / 2; @@ -1149,11 +1155,11 @@ public class BufTest { } } - private static void testCopyIntoBuf(Fixture fixture, Function bbAlloc) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + private static void testCopyIntoBuf(Fixture fixture, Function bbAlloc) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN).writeLong(0x0102030405060708L); - Buf buffer = bbAlloc.apply(8); + Buffer buffer = bbAlloc.apply(8); buffer.writerOffset(8); buf.copyInto(0, buffer, 0, buffer.capacity()); assertEquals((byte) 0x01, buffer.readByte()); @@ -1223,8 +1229,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void readableBytesMustMatchWhatWasWritten(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(16)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(16)) { buf.writeLong(0); assertEquals(Long.BYTES, buf.readableBytes()); buf.readShort(); @@ -1235,8 +1241,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void byteIterationOfBigEndianBuffers(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(0x28)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(0x28)) { buf.order(BIG_ENDIAN); // The byte order should have no impact. checkByteIteration(buf); buf.reset(); @@ -1247,8 +1253,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void byteIterationOfLittleEndianBuffers(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(0x28)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(0x28)) { buf.order(LITTLE_ENDIAN); // The byte order should have no impact. checkByteIteration(buf); buf.reset(); @@ -1256,7 +1262,7 @@ public class BufTest { } } - private static void checkByteIteration(Buf buf) { + private static void checkByteIteration(Buffer buf) { var cursor = buf.openCursor(); assertFalse(cursor.readByte()); assertFalse(cursor.readLong()); @@ -1317,7 +1323,7 @@ public class BufTest { assertEquals(woff, buf.writerOffset()); } - private static void checkByteIterationOfRegion(Buf buf) { + private static void checkByteIterationOfRegion(Buffer buf) { assertThrows(IllegalArgumentException.class, () -> buf.openCursor(-1, 1)); assertThrows(IllegalArgumentException.class, () -> buf.openCursor(1, -1)); assertThrows(IllegalArgumentException.class, () -> buf.openCursor(buf.capacity(), 1)); @@ -1392,8 +1398,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void reverseByteIterationOfBigEndianBuffers(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(0x28)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(0x28)) { buf.order(BIG_ENDIAN); // The byte order should have no impact. checkReverseByteIteration(buf); buf.reset(); @@ -1404,8 +1410,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void reverseByteIterationOfLittleEndianBuffers(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(0x28)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(0x28)) { buf.order(LITTLE_ENDIAN); // The byte order should have no impact. checkReverseByteIteration(buf); buf.reset(); @@ -1413,7 +1419,7 @@ public class BufTest { } } - private static void checkReverseByteIteration(Buf buf) { + private static void checkReverseByteIteration(Buffer buf) { var cursor = buf.openReverseCursor(); assertFalse(cursor.readByte()); assertFalse(cursor.readLong()); @@ -1473,7 +1479,7 @@ public class BufTest { assertEquals(woff, buf.writerOffset()); } - private static void checkReverseByteIterationOfRegion(Buf buf) { + private static void checkReverseByteIterationOfRegion(Buffer buf) { assertThrows(IllegalArgumentException.class, () -> buf.openReverseCursor(-1, 0)); assertThrows(IllegalArgumentException.class, () -> buf.openReverseCursor(0, -1)); assertThrows(IllegalArgumentException.class, () -> buf.openReverseCursor(0, 2)); @@ -1549,8 +1555,8 @@ public class BufTest { @ParameterizedTest @MethodSource("heapAllocators") public void heapBufferMustHaveZeroAddress(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThat(buf.nativeAddress()).isZero(); } } @@ -1558,8 +1564,8 @@ public class BufTest { @ParameterizedTest @MethodSource("directAllocators") public void directBufferMustHaveNonZeroAddress(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThat(buf.nativeAddress()).isNotZero(); } } @@ -1585,7 +1591,7 @@ public class BufTest { assertThat(sum).isLessThan(totalAllocated); } - private void allocateAndForget(Allocator allocator, int size) { + private void allocateAndForget(BufferAllocator allocator, int size) { allocator.allocate(size); } @@ -1611,12 +1617,12 @@ public class BufTest { @Test public void compositeBufferCanOnlyBeOwnedWhenAllConstituentBuffersAreOwned() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8)) { assertTrue(a.isOwned()); - Buf leakB; - try (Buf b = allocator.allocate(8)) { + Buffer leakB; + try (Buffer b = allocator.allocate(8)) { assertTrue(a.isOwned()); assertTrue(b.isOwned()); composite = allocator.compose(a, b); @@ -1635,15 +1641,15 @@ public class BufTest { @Test public void compositeBuffersCannotHaveDuplicateComponents() { - try (Allocator allocator = Allocator.heap(); - Buf a = allocator.allocate(4)) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer a = allocator.allocate(4)) { var e = assertThrows(IllegalArgumentException.class, () -> allocator.compose(a, a)); assertThat(e).hasMessageContaining("duplicate"); - try (Buf composite = allocator.compose(a)) { + try (Buffer composite = allocator.compose(a)) { a.close(); try { - e = assertThrows(IllegalArgumentException.class, () -> Allocator.extend(composite, a)); + e = assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(composite, a)); assertThat(e).hasMessageContaining("duplicate"); } finally { a.acquire(); @@ -1654,8 +1660,8 @@ public class BufTest { @Test public void compositeBufferFromSends() { - try (Allocator allocator = Allocator.heap(); - Buf composite = allocator.compose( + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer composite = allocator.compose( allocator.allocate(8).send(), allocator.allocate(8).send(), allocator.allocate(8).send())) { @@ -1666,20 +1672,20 @@ public class BufTest { @Test public void compositeBufferMustNotBeAllowedToContainThemselves() { - try (Allocator allocator = Allocator.heap()) { - Buf a = allocator.allocate(4); - Buf buf = allocator.compose(a); + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer a = allocator.allocate(4); + Buffer buf = allocator.compose(a); try (buf; a) { a.close(); try { - assertThrows(IllegalArgumentException.class, () -> Allocator.extend(buf, buf)); + assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(buf, buf)); assertTrue(buf.isOwned()); - try (Buf composite = allocator.compose(buf)) { + try (Buffer composite = allocator.compose(buf)) { // the composing increments the reference count of constituent buffers... // counter-act this so it can be extended: a.close(); // buf is now owned so it can be extended. try { - assertThrows(IllegalArgumentException.class, () -> Allocator.extend(buf, composite)); + assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(buf, composite)); } finally { a.acquire(); // restore the reference count to align with our try-with-resources structure. } @@ -1695,13 +1701,13 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void ensureWritableMustThrowForBorrowedBuffers(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { - try (Buf slice = buf.slice()) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + try (Buffer slice = buf.slice()) { assertThrows(IllegalStateException.class, () -> slice.ensureWritable(1)); assertThrows(IllegalStateException.class, () -> buf.ensureWritable(1)); } - try (Buf compose = allocator.compose(buf)) { + try (Buffer compose = allocator.compose(buf)) { assertThrows(IllegalStateException.class, () -> compose.ensureWritable(1)); assertThrows(IllegalStateException.class, () -> buf.ensureWritable(1)); } @@ -1711,8 +1717,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableMustThrowForNegativeSize(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IllegalArgumentException.class, () -> buf.ensureWritable(-1)); } } @@ -1720,8 +1726,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableMustThrowIfRequestedSizeWouldGrowBeyondMaxAllowed(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(512)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(512)) { assertThrows(IllegalArgumentException.class, () -> buf.ensureWritable(Integer.MAX_VALUE - 8)); } } @@ -1729,8 +1735,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableMustNotThrowWhenSpaceIsAlreadyAvailable(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.ensureWritable(8); buf.writeLong(1); assertThrows(IndexOutOfBoundsException.class, () -> buf.writeByte((byte) 1)); @@ -1740,8 +1746,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableMustExpandBufferCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThat(buf.writableBytes()).isEqualTo(8); buf.writeLong(0x0102030405060708L); assertThat(buf.writableBytes()).isEqualTo(0); @@ -1759,8 +1765,8 @@ public class BufTest { @Test public void ensureWritableMustExpandCapacityOfEmptyCompositeBuffer() { - try (Allocator allocator = Allocator.heap(); - Buf buf = allocator.compose()) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer buf = allocator.compose()) { assertThat(buf.writableBytes()).isEqualTo(0); buf.ensureWritable(8); assertThat(buf.writableBytes()).isGreaterThanOrEqualTo(8); @@ -1775,13 +1781,13 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void mustBeAbleToSliceAfterEnsureWritable(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(4)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(4)) { buf.ensureWritable(8); assertThat(buf.writableBytes()).isGreaterThanOrEqualTo(8); assertThat(buf.capacity()).isGreaterThanOrEqualTo(8); buf.writeLong(0x0102030405060708L); - try (Buf slice = buf.slice()) { + try (Buffer slice = buf.slice()) { assertEquals(0x0102030405060708L, slice.readLong()); } } @@ -1790,9 +1796,9 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableOnCompositeBuffersMustRespectExistingBigEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { - Buf composite; - try (Buf a = allocator.allocate(4, BIG_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator()) { + Buffer composite; + try (Buffer a = allocator.allocate(4, BIG_ENDIAN)) { composite = allocator.compose(a); } try (composite) { @@ -1807,9 +1813,9 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableOnCompositeBuffersMustRespectExistingLittleEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { - Buf composite; - try (Buf a = allocator.allocate(4, LITTLE_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator()) { + Buffer composite; + try (Buffer a = allocator.allocate(4, LITTLE_ENDIAN)) { composite = allocator.compose(a); } try (composite) { @@ -1824,8 +1830,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableWithCompactionMustNotAllocateIfCompactionIsEnough(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(64)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(64)) { while (buf.writableBytes() > 0) { buf.writeByte((byte) 42); } @@ -1847,10 +1853,10 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void pooledBuffersMustResetStateBeforeReuse(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf expected = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer expected = allocator.allocate(8)) { for (int i = 0; i < 10; i++) { - try (Buf buf = allocator.allocate(8)) { + try (Buffer buf = allocator.allocate(8)) { assertEquals(expected.capacity(), buf.capacity()); assertEquals(expected.readableBytes(), buf.readableBytes()); assertEquals(expected.readerOffset(), buf.readerOffset()); @@ -1878,30 +1884,30 @@ public class BufTest { @Test public void emptyCompositeBufferMustUseNativeByteOrder() { - try (Allocator allocator = Allocator.heap(); - Buf composite = allocator.compose()) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer composite = allocator.compose()) { assertThat(composite.order()).isEqualTo(ByteOrder.nativeOrder()); } } @Test public void extendOnNonCompositeBufferMustThrow() { - try (Allocator allocator = Allocator.heap(); - Buf a = allocator.allocate(8); - Buf b = allocator.allocate(8)) { - var exc = assertThrows(IllegalArgumentException.class, () -> Allocator.extend(a, b)); + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer a = allocator.allocate(8); + Buffer b = allocator.allocate(8)) { + var exc = assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(a, b)); assertThat(exc).hasMessageContaining("Expected").hasMessageContaining("composite"); } } @Test public void extendingNonOwnedCompositeBufferMustThrow() { - try (Allocator allocator = Allocator.heap(); - Buf a = allocator.allocate(8); - Buf b = allocator.allocate(8); - Buf composed = allocator.compose(a)) { - try (Buf ignore = composed.acquire()) { - var exc = assertThrows(IllegalStateException.class, () -> Allocator.extend(composed, b)); + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer a = allocator.allocate(8); + Buffer b = allocator.allocate(8); + Buffer composed = allocator.compose(a)) { + try (Buffer ignore = composed.acquire()) { + var exc = assertThrows(IllegalStateException.class, () -> BufferAllocator.extend(composed, b)); assertThat(exc).hasMessageContaining("owned"); } } @@ -1909,13 +1915,14 @@ public class BufTest { @Test public void extendingCompositeBufferWithItselfMustThrow() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8)) { composite = allocator.compose(a); } try (composite) { - var exc = assertThrows(IllegalArgumentException.class, () -> Allocator.extend(composite, composite)); + var exc = assertThrows(IllegalArgumentException.class, + () -> BufferAllocator.extend(composite, composite)); assertThat(exc).hasMessageContaining("cannot be extended"); } } @@ -1923,21 +1930,21 @@ public class BufTest { @Test public void extendingWithZeroCapacityBufferHasNoEffect() { - try (Allocator allocator = Allocator.heap(); - Buf composite = allocator.compose()) { - Allocator.extend(composite, composite); + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer composite = allocator.compose()) { + BufferAllocator.extend(composite, composite); assertThat(composite.capacity()).isZero(); assertThat(composite.countComponents()).isZero(); } - try (Allocator allocator = Allocator.heap()) { - Buf a = allocator.allocate(1); - Buf composite = allocator.compose(a); + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer a = allocator.allocate(1); + Buffer composite = allocator.compose(a); a.close(); assertTrue(composite.isOwned()); assertThat(composite.capacity()).isOne(); assertThat(composite.countComponents()).isOne(); - try (Buf b = allocator.compose()) { - Allocator.extend(composite, b); + try (Buffer b = allocator.compose()) { + BufferAllocator.extend(composite, b); } assertTrue(composite.isOwned()); assertThat(composite.capacity()).isOne(); @@ -1947,19 +1954,19 @@ public class BufTest { @Test public void extendingCompositeBufferWithNullMustThrow() { - try (Allocator allocator = Allocator.heap(); - Buf composite = allocator.compose()) { - assertThrows(NullPointerException.class, () -> Allocator.extend(composite, null)); + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer composite = allocator.compose()) { + assertThrows(NullPointerException.class, () -> BufferAllocator.extend(composite, null)); } } @Test public void extendingCompositeBufferMustIncreaseCapacityByGivenBigEndianBuffer() { - try (Allocator allocator = Allocator.heap(); - Buf composite = allocator.compose()) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer composite = allocator.compose()) { assertThat(composite.capacity()).isZero(); - try (Buf buf = allocator.allocate(8, BIG_ENDIAN)) { - Allocator.extend(composite, buf); + try (Buffer buf = allocator.allocate(8, BIG_ENDIAN)) { + BufferAllocator.extend(composite, buf); } assertThat(composite.capacity()).isEqualTo(8); composite.writeLong(0x0102030405060708L); @@ -1969,11 +1976,11 @@ public class BufTest { @Test public void extendingCompositeBufferMustIncreaseCapacityByGivenLittleEndianBuffer() { - try (Allocator allocator = Allocator.heap(); - Buf composite = allocator.compose()) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer composite = allocator.compose()) { assertThat(composite.capacity()).isZero(); - try (Buf buf = allocator.allocate(8, LITTLE_ENDIAN)) { - Allocator.extend(composite, buf); + try (Buffer buf = allocator.allocate(8, LITTLE_ENDIAN)) { + BufferAllocator.extend(composite, buf); } assertThat(composite.capacity()).isEqualTo(8); composite.writeLong(0x0102030405060708L); @@ -1983,14 +1990,14 @@ public class BufTest { @Test public void extendingBigEndianCompositeBufferMustThrowIfExtensionIsLittleEndian() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8, BIG_ENDIAN)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8, BIG_ENDIAN)) { composite = allocator.compose(a); } try (composite) { - try (Buf b = allocator.allocate(8, LITTLE_ENDIAN)) { - var exc = assertThrows(IllegalArgumentException.class, () -> Allocator.extend(composite, b)); + try (Buffer b = allocator.allocate(8, LITTLE_ENDIAN)) { + var exc = assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(composite, b)); assertThat(exc).hasMessageContaining("byte order"); } } @@ -1999,14 +2006,14 @@ public class BufTest { @Test public void extendingLittleEndianCompositeBufferMustThrowIfExtensionIsBigEndian() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8, LITTLE_ENDIAN)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8, LITTLE_ENDIAN)) { composite = allocator.compose(a); } try (composite) { - try (Buf b = allocator.allocate(8, BIG_ENDIAN)) { - var exc = assertThrows(IllegalArgumentException.class, () -> Allocator.extend(composite, b)); + try (Buffer b = allocator.allocate(8, BIG_ENDIAN)) { + var exc = assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(composite, b)); assertThat(exc).hasMessageContaining("byte order"); } } @@ -2015,10 +2022,10 @@ public class BufTest { @Test public void emptyCompositeBufferMustAllowExtendingWithBufferWithBigEndianByteOrder() { - try (Allocator allocator = Allocator.heap()) { - try (Buf composite = allocator.compose()) { - try (Buf b = allocator.allocate(8, BIG_ENDIAN)) { - Allocator.extend(composite, b); + try (BufferAllocator allocator = BufferAllocator.heap()) { + try (Buffer composite = allocator.compose()) { + try (Buffer b = allocator.allocate(8, BIG_ENDIAN)) { + BufferAllocator.extend(composite, b); assertThat(composite.order()).isEqualTo(BIG_ENDIAN); } } @@ -2027,10 +2034,10 @@ public class BufTest { @Test public void emptyCompositeBufferMustAllowExtendingWithBufferWithLittleEndianByteOrder() { - try (Allocator allocator = Allocator.heap()) { - try (Buf composite = allocator.compose()) { - try (Buf b = allocator.allocate(8, LITTLE_ENDIAN)) { - Allocator.extend(composite, b); + try (BufferAllocator allocator = BufferAllocator.heap()) { + try (Buffer composite = allocator.compose()) { + try (Buffer b = allocator.allocate(8, LITTLE_ENDIAN)) { + BufferAllocator.extend(composite, b); assertThat(composite.order()).isEqualTo(LITTLE_ENDIAN); } } @@ -2039,10 +2046,10 @@ public class BufTest { @Test public void emptyCompositeBufferMustAllowExtendingWithReadOnlyBuffer() { - try (Allocator allocator = Allocator.heap()) { - try (Buf composite = allocator.compose()) { - try (Buf b = allocator.allocate(8).readOnly(true)) { - Allocator.extend(composite, b); + try (BufferAllocator allocator = BufferAllocator.heap()) { + try (Buffer composite = allocator.compose()) { + try (Buffer b = allocator.allocate(8).readOnly(true)) { + BufferAllocator.extend(composite, b); assertTrue(composite.readOnly()); } } @@ -2051,16 +2058,16 @@ public class BufTest { @Test public void whenExtendingCompositeBufferWithWriteOffsetAtCapacityExtensionWriteOffsetCanBeNonZero() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8)) { composite = allocator.compose(a); } try (composite) { composite.writeLong(0); - try (Buf b = allocator.allocate(8)) { + try (Buffer b = allocator.allocate(8)) { b.writeInt(1); - Allocator.extend(composite, b); + BufferAllocator.extend(composite, b); assertThat(composite.capacity()).isEqualTo(16); assertThat(composite.writerOffset()).isEqualTo(12); } @@ -2070,19 +2077,19 @@ public class BufTest { @Test public void whenExtendingCompositeBufferWithWriteOffsetLessThanCapacityExtensionWriteOffsetMustZero() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8)) { composite = allocator.compose(a); } try (composite) { composite.writeInt(0); - try (Buf b = allocator.allocate(8)) { + try (Buffer b = allocator.allocate(8)) { b.writeInt(1); - var exc = assertThrows(IllegalArgumentException.class, () -> Allocator.extend(composite, b)); + var exc = assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(composite, b)); assertThat(exc).hasMessageContaining("unwritten gap"); b.writerOffset(0); - Allocator.extend(composite, b); + BufferAllocator.extend(composite, b); assertThat(composite.capacity()).isEqualTo(16); assertThat(composite.writerOffset()).isEqualTo(4); } @@ -2092,18 +2099,18 @@ public class BufTest { @Test public void whenExtendingCompositeBufferWithReadOffsetAtCapacityExtensionReadOffsetCanBeNonZero() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8)) { composite = allocator.compose(a); } try (composite) { composite.writeLong(0); composite.readLong(); - try (Buf b = allocator.allocate(8)) { + try (Buffer b = allocator.allocate(8)) { b.writeInt(1); b.readInt(); - Allocator.extend(composite, b); + BufferAllocator.extend(composite, b); assertThat(composite.capacity()).isEqualTo(16); assertThat(composite.writerOffset()).isEqualTo(12); } @@ -2113,21 +2120,21 @@ public class BufTest { @Test public void whenExtendingCompositeBufferWithReadOffsetLessThanCapacityExtensionReadOffsetMustZero() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8)) { composite = allocator.compose(a); } try (composite) { composite.writeLong(0); composite.readInt(); - try (Buf b = allocator.allocate(8)) { + try (Buffer b = allocator.allocate(8)) { b.writeInt(1); b.readInt(); - var exc = assertThrows(IllegalArgumentException.class, () -> Allocator.extend(composite, b)); + var exc = assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(composite, b)); assertThat(exc).hasMessageContaining("unread gap"); b.readerOffset(0); - Allocator.extend(composite, b); + BufferAllocator.extend(composite, b); assertThat(composite.capacity()).isEqualTo(16); assertThat(composite.writerOffset()).isEqualTo(12); assertThat(composite.readerOffset()).isEqualTo(4); @@ -2138,9 +2145,9 @@ public class BufTest { @Test public void composeMustThrowWhenBuffersHaveMismatchedByteOrder() { - try (Allocator allocator = Allocator.heap(); - Buf a = allocator.allocate(4, BIG_ENDIAN); - Buf b = allocator.allocate(4, LITTLE_ENDIAN)) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer a = allocator.allocate(4, BIG_ENDIAN); + Buffer b = allocator.allocate(4, LITTLE_ENDIAN)) { assertThrows(IllegalArgumentException.class, () -> allocator.compose(a, b)); } } @@ -2148,10 +2155,10 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void bifurcateOfNonOwnedBufferMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.writeInt(1); - try (Buf acquired = buf.acquire()) { + try (Buffer acquired = buf.acquire()) { var exc = assertThrows(IllegalStateException.class, () -> acquired.bifurcate()); assertThat(exc).hasMessageContaining("owned"); } @@ -2161,11 +2168,11 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void bifurcatedPartMustContainFirstHalfOfBuffer(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(16).order(BIG_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(16).order(BIG_ENDIAN)) { buf.writeLong(0x0102030405060708L); assertThat(buf.readByte()).isEqualTo((byte) 0x01); - try (Buf bif = buf.bifurcate()) { + try (Buffer bif = buf.bifurcate()) { // Original buffer: assertThat(buf.capacity()).isEqualTo(8); assertThat(buf.readerOffset()).isZero(); @@ -2197,12 +2204,12 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void bifurcatedPartsMustBeIndividuallySendable(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(16).order(BIG_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(16).order(BIG_ENDIAN)) { buf.writeLong(0x0102030405060708L); assertThat(buf.readByte()).isEqualTo((byte) 0x01); - try (Buf sentBif = buf.bifurcate().send().receive()) { - try (Buf sentBuf = buf.send().receive()) { + try (Buffer sentBif = buf.bifurcate().send().receive()) { + try (Buffer sentBuf = buf.send().receive()) { assertThat(sentBuf.capacity()).isEqualTo(8); assertThat(sentBuf.readerOffset()).isZero(); assertThat(sentBuf.writerOffset()).isZero(); @@ -2226,12 +2233,12 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void mustBePossibleToBifurcateMoreThanOnce(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(16).order(BIG_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(16).order(BIG_ENDIAN)) { buf.writeLong(0x0102030405060708L); - try (Buf a = buf.bifurcate()) { + try (Buffer a = buf.bifurcate()) { a.writerOffset(4); - try (Buf b = a.bifurcate()) { + try (Buffer b = a.bifurcate()) { assertEquals(0x01020304, b.readInt()); a.writerOffset(4); assertEquals(0x05060708, a.readInt()); @@ -2239,7 +2246,7 @@ public class BufTest { assertThrows(IndexOutOfBoundsException.class, () -> a.readByte()); buf.writeLong(0xA1A2A3A4A5A6A7A8L); buf.writerOffset(4); - try (Buf c = buf.bifurcate()) { + try (Buffer c = buf.bifurcate()) { assertEquals(0xA1A2A3A4, c.readInt()); buf.writerOffset(4); assertEquals(0xA5A6A7A8, buf.readInt()); @@ -2254,14 +2261,14 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void bifurcatedBufferMustHaveSameByteOrderAsParent(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8).order(BIG_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8).order(BIG_ENDIAN)) { buf.writeLong(0x0102030405060708L); - try (Buf a = buf.bifurcate()) { + try (Buffer a = buf.bifurcate()) { assertThat(a.order()).isEqualTo(BIG_ENDIAN); a.order(LITTLE_ENDIAN); a.writerOffset(4); - try (Buf b = a.bifurcate()) { + try (Buffer b = a.bifurcate()) { assertThat(b.order()).isEqualTo(LITTLE_ENDIAN); assertThat(buf.order()).isEqualTo(BIG_ENDIAN); } @@ -2272,10 +2279,10 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableOnBifurcatedBuffers(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.writeLong(0x0102030405060708L); - try (Buf a = buf.bifurcate()) { + try (Buffer a = buf.bifurcate()) { assertEquals(0x0102030405060708L, a.readLong()); a.ensureWritable(8); a.writeLong(0xA1A2A3A4A5A6A7A8L); @@ -2291,12 +2298,12 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableOnBifurcatedBuffersWithOddOffsets(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(10).order(BIG_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(10).order(BIG_ENDIAN)) { buf.writeLong(0x0102030405060708L); buf.writeByte((byte) 0x09); buf.readByte(); - try (Buf a = buf.bifurcate()) { + try (Buffer a = buf.bifurcate()) { assertEquals(0x0203040506070809L, a.readLong()); a.ensureWritable(8); a.writeLong(0xA1A2A3A4A5A6A7A8L); @@ -2311,22 +2318,22 @@ public class BufTest { @Test public void bifurcateOnEmptyBigEndianCompositeBuffer() { - try (Allocator allocator = Allocator.heap(); - Buf buf = allocator.compose().order(BIG_ENDIAN)) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer buf = allocator.compose().order(BIG_ENDIAN)) { verifyBifurcateEmptyCompositeBuffer(buf); } } @Test public void bifurcateOnEmptyLittleEndianCompositeBuffer() { - try (Allocator allocator = Allocator.heap(); - Buf buf = allocator.compose().order(LITTLE_ENDIAN)) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer buf = allocator.compose().order(LITTLE_ENDIAN)) { verifyBifurcateEmptyCompositeBuffer(buf); } } - private static void verifyBifurcateEmptyCompositeBuffer(Buf buf) { - try (Buf a = buf.bifurcate()) { + private static void verifyBifurcateEmptyCompositeBuffer(Buffer buf) { + try (Buffer a = buf.bifurcate()) { a.ensureWritable(4); buf.ensureWritable(4); a.writeInt(1); @@ -2340,12 +2347,12 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void bifurcatedBuffersMustBeAccessibleInOtherThreads(Fixture fixture) throws Exception { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.writeInt(42); var send = buf.bifurcate().send(); var fut = executor.submit(() -> { - try (Buf receive = send.receive()) { + try (Buffer receive = send.receive()) { assertEquals(42, receive.readInt()); receive.readerOffset(0).writerOffset(0).writeInt(24); assertEquals(24, receive.readInt()); @@ -2360,8 +2367,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void sendMustNotMakeBifurcatedBuffersInaccessible(Fixture fixture) throws Exception { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(16)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(16)) { buf.writeInt(64); var bifA = buf.bifurcate(); buf.writeInt(42); @@ -2369,7 +2376,7 @@ public class BufTest { buf.writeInt(72); var bifB = buf.bifurcate(); var fut = executor.submit(() -> { - try (Buf receive = send.receive()) { + try (Buffer receive = send.receive()) { assertEquals(42, receive.readInt()); } }); @@ -2384,8 +2391,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void compactMustDiscardReadBytes(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(16, BIG_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(16, BIG_ENDIAN)) { buf.writeLong(0x0102030405060708L).writeInt(0x090A0B0C); assertEquals(0x01020304, buf.readInt()); assertEquals(12, buf.writerOffset()); @@ -2406,11 +2413,11 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void compactMustThrowForUnownedBuffer(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8, BIG_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8, BIG_ENDIAN)) { buf.writeLong(0x0102030405060708L); assertEquals((byte) 0x01, buf.readByte()); - try (Buf ignore = buf.acquire()) { + try (Buffer ignore = buf.acquire()) { assertThrows(IllegalStateException.class, () -> buf.compact()); assertEquals(1, buf.readerOffset()); } @@ -2421,8 +2428,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void readOnlyBufferMustPreventWriteAccess(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { var b = buf.readOnly(true); assertThat(b).isSameAs(buf); verifyWriteInaccessible(buf); @@ -2432,8 +2439,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void readOnlyBufferMustBecomeWritableAgainAfterTogglingReadOnlyOff(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertFalse(buf.readOnly()); buf.readOnly(true); assertTrue(buf.readOnly()); @@ -2446,7 +2453,7 @@ public class BufTest { } } - private static void verifyWriteAccessible(Buf buf) { + private static void verifyWriteAccessible(Buffer buf) { buf.writerOffset(0).writeByte((byte) 32); assertThat(buf.readerOffset(0).readByte()).isEqualTo((byte) 32); buf.writerOffset(0).writeUnsignedByte(32); @@ -2501,18 +2508,18 @@ public class BufTest { buf.ensureWritable(1); } buf.fill((byte) 0); - try (Allocator allocator = Allocator.heap(); - Buf source = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer source = allocator.allocate(8)) { source.copyInto(0, buf, 0, 1); } } @Test public void composingReadOnlyBuffersMustCreateReadOnlyCompositeBuffer() { - try (Allocator allocator = Allocator.heap(); - Buf a = allocator.allocate(4).readOnly(true); - Buf b = allocator.allocate(4).readOnly(true); - Buf composite = allocator.compose(a, b)) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer a = allocator.allocate(4).readOnly(true); + Buffer b = allocator.allocate(4).readOnly(true); + Buffer composite = allocator.compose(a, b)) { assertTrue(composite.readOnly()); verifyWriteInaccessible(composite); } @@ -2521,11 +2528,11 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void readOnlyBufferMustRemainReadOnlyAfterSend(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.readOnly(true); var send = buf.send(); - try (Buf receive = send.receive()) { + try (Buffer receive = send.receive()) { assertTrue(receive.readOnly()); verifyWriteInaccessible(receive); } @@ -2534,11 +2541,11 @@ public class BufTest { @Test public void readOnlyBufferMustRemainReadOnlyAfterSendForEmptyCompositeBuffer() { - try (Allocator allocator = Allocator.heap(); - Buf buf = allocator.compose()) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer buf = allocator.compose()) { buf.readOnly(true); var send = buf.send(); - try (Buf receive = send.receive()) { + try (Buffer receive = send.receive()) { assertTrue(receive.readOnly()); } } @@ -2547,9 +2554,9 @@ public class BufTest { @ParameterizedTest @MethodSource("pooledAllocators") public void readOnlyBufferMustNotBeReadOnlyAfterBeingReusedFromPool(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { + try (BufferAllocator allocator = fixture.createAllocator()) { for (int i = 0; i < 1000; i++) { - try (Buf buf = allocator.allocate(8)) { + try (Buffer buf = allocator.allocate(8)) { assertFalse(buf.readOnly()); buf.readOnly(true); assertTrue(buf.readOnly()); @@ -2561,10 +2568,10 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void acquireOfReadOnlyBufferMustBeReadOnly(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.readOnly(true); - try (Buf acquire = buf.acquire()) { + try (Buffer acquire = buf.acquire()) { assertTrue(acquire.readOnly()); } } @@ -2573,11 +2580,11 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void sliceOfReadOnlyBufferMustBeReadOnly(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.writeLong(0x0102030405060708L); buf.readOnly(true); - try (Buf slice = buf.slice()) { + try (Buffer slice = buf.slice()) { assertTrue(slice.readOnly()); } } @@ -2586,11 +2593,11 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void bifurcateOfReadOnlyBufferMustBeReadOnly(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(16)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(16)) { buf.writeLong(0x0102030405060708L); buf.readOnly(true); - try (Buf bifurcate = buf.bifurcate()) { + try (Buffer bifurcate = buf.bifurcate()) { assertTrue(bifurcate.readOnly()); assertTrue(buf.readOnly()); } @@ -2599,9 +2606,9 @@ public class BufTest { @Test public void composingReadOnlyAndWritableBuffersMustThrow() { - try (Allocator allocator = Allocator.heap(); - Buf a = allocator.allocate(8).readOnly(true); - Buf b = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap(); + Buffer a = allocator.allocate(8).readOnly(true); + Buffer b = allocator.allocate(8)) { assertThrows(IllegalArgumentException.class, () -> allocator.compose(a, b)); assertThrows(IllegalArgumentException.class, () -> allocator.compose(b, a)); assertThrows(IllegalArgumentException.class, () -> allocator.compose(a, b, a)); @@ -2611,26 +2618,26 @@ public class BufTest { @Test public void compositeWritableBufferCannotBeExtendedWithReadOnlyBuffer() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8)) { composite = allocator.compose(a); } - try (composite; Buf b = allocator.allocate(8).readOnly(true)) { - assertThrows(IllegalArgumentException.class, () -> Allocator.extend(composite, b)); + try (composite; Buffer b = allocator.allocate(8).readOnly(true)) { + assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(composite, b)); } } } @Test public void compositeReadOnlyBufferCannotBeExtendedWithWritableBuffer() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(8).readOnly(true)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(8).readOnly(true)) { composite = allocator.compose(a); } - try (composite; Buf b = allocator.allocate(8)) { - assertThrows(IllegalArgumentException.class, () -> Allocator.extend(composite, b)); + try (composite; Buffer b = allocator.allocate(8)) { + assertThrows(IllegalArgumentException.class, () -> BufferAllocator.extend(composite, b)); } } } @@ -2638,8 +2645,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void compactOnReadOnlyBufferMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.readOnly(true); assertThrows(IllegalStateException.class, () -> buf.compact()); } @@ -2648,8 +2655,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void ensureWritableOnReadOnlyBufferMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.readOnly(true); assertThrows(IllegalStateException.class, () -> buf.ensureWritable(1)); } @@ -2658,10 +2665,10 @@ public class BufTest { @ParameterizedTest @MethodSource("nonSliceAllocators") public void copyIntoOnReadOnlyBufferMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf dest = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer dest = allocator.allocate(8)) { dest.readOnly(true); - try (Buf src = allocator.allocate(8)) { + try (Buffer src = allocator.allocate(8)) { assertThrows(IllegalStateException.class, () -> src.copyInto(0, dest, 0, 1)); } } @@ -2671,8 +2678,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonCompositeAllocators") public void componentCountOfNonCompositeBufferMustBeOne(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThat(buf.countComponents()).isOne(); } } @@ -2680,8 +2687,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonCompositeAllocators") public void readableComponentCountMustBeOneIfThereAreReadableBytes(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThat(buf.countReadableComponents()).isZero(); buf.writeByte((byte) 1); assertThat(buf.countReadableComponents()).isOne(); @@ -2691,8 +2698,8 @@ public class BufTest { @ParameterizedTest @MethodSource("nonCompositeAllocators") public void writableComponentCountMustBeOneIfThereAreWritableBytes(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThat(buf.countWritableComponents()).isOne(); buf.writeLong(1); assertThat(buf.countWritableComponents()).isZero(); @@ -2701,12 +2708,12 @@ public class BufTest { @Test public void compositeBufferComponentCountMustBeTransitiveSum() { - try (Allocator allocator = Allocator.heap()) { - Buf buf; - try (Buf a = allocator.allocate(8); - Buf b = allocator.allocate(8); - Buf c = allocator.allocate(8); - Buf x = allocator.compose(b, c)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer buf; + try (Buffer a = allocator.allocate(8); + Buffer b = allocator.allocate(8); + Buffer c = allocator.allocate(8); + Buffer x = allocator.compose(b, c)) { buf = allocator.compose(a, x); } assertThat(buf.countComponents()).isEqualTo(3); @@ -2736,11 +2743,12 @@ public class BufTest { @ParameterizedTest @MethodSource("nonCompositeAllocators") public void forEachReadableMustVisitBuffer(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf bufBERW = allocator.allocate(8).order(BIG_ENDIAN).writeLong(0x0102030405060708L); - Buf bufLERW = allocator.allocate(8).order(LITTLE_ENDIAN).writeLong(0x0102030405060708L); - Buf bufBERO = allocator.allocate(8).order(BIG_ENDIAN).writeLong(0x0102030405060708L).readOnly(true); - Buf bufLERO = allocator.allocate(8).order(LITTLE_ENDIAN).writeLong(0x0102030405060708L).readOnly(true)) { + long value = 0x0102030405060708L; + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer bufBERW = allocator.allocate(8).order(BIG_ENDIAN).writeLong(value); + Buffer bufLERW = allocator.allocate(8).order(LITTLE_ENDIAN).writeLong(value); + Buffer bufBERO = allocator.allocate(8).order(BIG_ENDIAN).writeLong(value).readOnly(true); + Buffer bufLERO = allocator.allocate(8).order(LITTLE_ENDIAN).writeLong(value).readOnly(true)) { verifyForEachReadableSingleComponent(fixture, bufBERW); verifyForEachReadableSingleComponent(fixture, bufLERW); verifyForEachReadableSingleComponent(fixture, bufBERO); @@ -2748,7 +2756,7 @@ public class BufTest { } } - private static void verifyForEachReadableSingleComponent(Fixture fixture, Buf buf) { + private static void verifyForEachReadableSingleComponent(Fixture fixture, Buffer buf) { buf.forEachReadable(0, (index, component) -> { var buffer = component.readableBuffer(); assertThat(buffer.position()).isZero(); @@ -2778,11 +2786,11 @@ public class BufTest { @Test public void forEachReadableMustVisitAllReadableConstituentBuffersInOrder() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(4); - Buf b = allocator.allocate(4); - Buf c = allocator.allocate(4)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(4); + Buffer b = allocator.allocate(4); + Buffer c = allocator.allocate(4)) { a.writeInt(1); b.writeInt(2); c.writeInt(3); @@ -2805,8 +2813,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void forEachReadableMustReturnNegativeCountWhenProcessorReturnsFalse(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.writeLong(0x0102030405060708L); int count = buf.forEachReadable(0, (index, component) -> false); assertEquals(-1, count); @@ -2815,11 +2823,11 @@ public class BufTest { @Test public void forEachReadableMustStopIterationWhenProcessorReturnsFalse() { - try (Allocator allocator = Allocator.heap()) { - Buf composite; - try (Buf a = allocator.allocate(4); - Buf b = allocator.allocate(4); - Buf c = allocator.allocate(4)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer composite; + try (Buffer a = allocator.allocate(4); + Buffer b = allocator.allocate(4); + Buffer c = allocator.allocate(4)) { a.writeInt(1); b.writeInt(2); c.writeInt(3); @@ -2845,7 +2853,7 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void forEachReadableOnClosedBufferMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { + try (BufferAllocator allocator = fixture.createAllocator()) { var buf = allocator.allocate(8); buf.writeLong(0); buf.close(); @@ -2856,11 +2864,11 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void forEachReadableMustAllowCollectingBuffersInArray(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { - Buf buf; - try (Buf a = allocator.allocate(4); - Buf b = allocator.allocate(4); - Buf c = allocator.allocate(4)) { + try (BufferAllocator allocator = fixture.createAllocator()) { + Buffer buf; + try (Buffer a = allocator.allocate(4); + Buffer b = allocator.allocate(4); + Buffer c = allocator.allocate(4)) { buf = allocator.compose(a, b, c); } int i = 1; @@ -2885,15 +2893,15 @@ public class BufTest { @ParameterizedTest @MethodSource("nonCompositeAllocators") public void forEachWritableMustVisitBuffer(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf bufBERW = allocator.allocate(8).order(BIG_ENDIAN); - Buf bufLERW = allocator.allocate(8).order(LITTLE_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer bufBERW = allocator.allocate(8).order(BIG_ENDIAN); + Buffer bufLERW = allocator.allocate(8).order(LITTLE_ENDIAN)) { verifyForEachWritableSingleComponent(fixture, bufBERW); verifyForEachWritableSingleComponent(fixture, bufLERW); } } - private static void verifyForEachWritableSingleComponent(Fixture fixture, Buf buf) { + private static void verifyForEachWritableSingleComponent(Fixture fixture, Buffer buf) { buf.forEachWritable(0, (index, component) -> { var buffer = component.writableBuffer(); assertThat(buffer.position()).isZero(); @@ -2929,11 +2937,11 @@ public class BufTest { @Test public void forEachWritableMustVisitAllWritableConstituentBuffersInOrder() { - try (Allocator allocator = Allocator.heap()) { - Buf buf; - try (Buf a = allocator.allocate(8); - Buf b = allocator.allocate(8); - Buf c = allocator.allocate(8)) { + try (BufferAllocator allocator = BufferAllocator.heap()) { + Buffer buf; + try (Buffer a = allocator.allocate(8); + Buffer b = allocator.allocate(8); + Buffer c = allocator.allocate(8)) { buf = allocator.compose(a, b, c); } buf.order(BIG_ENDIAN); @@ -2951,8 +2959,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void forEachWritableMustReturnNegativeCountWhenProcessorReturnsFalse(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int count = buf.forEachWritable(0, (index, component) -> false); assertEquals(-1, count); } @@ -2961,8 +2969,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void forEachWritableMustStopIterationWhenProcessorRetursFalse(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { AtomicInteger counter = new AtomicInteger(); buf.forEachWritable(0, (index, component) -> { counter.incrementAndGet(); @@ -2975,8 +2983,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void forEachWritableChangesMadeToByteBufferComponentMustBeReflectedInBuffer(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(9).order(BIG_ENDIAN)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(9).order(BIG_ENDIAN)) { buf.writeByte((byte) 0xFF); AtomicInteger writtenCounter = new AtomicInteger(); buf.forEachWritable(0, (index, component) -> { @@ -2995,8 +3003,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void changesMadeToByteBufferComponentsShouldBeReflectedInBuffer(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { AtomicInteger counter = new AtomicInteger(); buf.forEachWritable(0, (index, component) -> { var buffer = component.writableBuffer(); @@ -3015,8 +3023,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void forEachWritableOnClosedBufferMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator()) { - Buf buf = allocator.allocate(8); + try (BufferAllocator allocator = fixture.createAllocator()) { + Buffer buf = allocator.allocate(8); buf.close(); assertThrows(IllegalStateException.class, () -> buf.forEachWritable(0, (index, component) -> true)); } @@ -3025,8 +3033,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void forEachWritableOnReadOnlyBufferMustThrow(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8).readOnly(true)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8).readOnly(true)) { assertThrows(IllegalStateException.class, () -> buf.forEachWritable(0, (index, component) -> true)); } } @@ -3034,8 +3042,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") public void forEachWritableMustAllowCollectingBuffersInArray(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { ByteBuffer[] buffers = new ByteBuffer[buf.countWritableComponents()]; buf.forEachWritable(0, (index, component) -> { buffers[index] = component.writableBuffer(); @@ -3060,8 +3068,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfByteMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); byte value = 0x01; @@ -3076,8 +3084,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfByteMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -3094,8 +3102,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfByteMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); byte value = 0x01; @@ -3111,8 +3119,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfByteMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getByte(-1)); } } @@ -3120,8 +3128,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfByteReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getByte(-1)); } } @@ -3129,8 +3137,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfByteMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { byte value = 0x01; buf.writeByte(value); assertEquals(value, buf.getByte(0)); @@ -3140,8 +3148,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfByteMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); byte value = 0x01; buf.writeByte(value); @@ -3153,8 +3161,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfByteMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { byte value = 0x01; buf.writeByte(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getByte(-1)); @@ -3164,8 +3172,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfByteReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { byte value = 0x01; buf.writeByte(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getByte(-1)); @@ -3175,8 +3183,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfByteMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getByte(0)); } } @@ -3184,8 +3192,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfByteReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getByte(0)); } } @@ -3193,8 +3201,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedByteMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x01; @@ -3209,8 +3217,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedByteMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -3227,8 +3235,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedByteMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x01; @@ -3244,8 +3252,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedByteReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x01; @@ -3261,8 +3269,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedByteMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedByte(-1)); } } @@ -3270,8 +3278,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedByteReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedByte(-1)); } } @@ -3279,8 +3287,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedByteMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x01; buf.writeUnsignedByte(value); assertEquals(value, buf.getUnsignedByte(0)); @@ -3290,8 +3298,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedByteMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x01; buf.writeUnsignedByte(value); @@ -3303,8 +3311,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedByteMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x01; buf.writeUnsignedByte(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedByte(1)); @@ -3315,8 +3323,8 @@ public class BufTest { @MethodSource("allocators") void offsettedGetOfUnsignedByteReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x01; buf.writeUnsignedByte(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedByte(1)); @@ -3326,8 +3334,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedByteMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedByte(0)); } } @@ -3335,8 +3343,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedByteReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedByte(0)); } } @@ -3344,8 +3352,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfByteMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(8); byte value = 0x01; @@ -3359,8 +3367,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfByteMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); byte value = 0x01; buf.writeByte(value); @@ -3379,8 +3387,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfByteMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); byte value = 0x01; assertThrows(IndexOutOfBoundsException.class, () -> buf.setByte(-1, value)); @@ -3393,8 +3401,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfByteMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); byte value = 0x01; assertThrows(IndexOutOfBoundsException.class, () -> buf.setByte(8, value)); @@ -3407,8 +3415,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfByteMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); byte value = 0x01; buf.setByte(0, value); @@ -3427,8 +3435,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfUnsignedByteMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(8); int value = 0x01; @@ -3442,8 +3450,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfUnsignedByteMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x01; buf.writeUnsignedByte(value); @@ -3462,8 +3470,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedByteMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x01; assertThrows(IndexOutOfBoundsException.class, () -> buf.setUnsignedByte(-1, value)); @@ -3476,8 +3484,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedByteMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x01; assertThrows(IndexOutOfBoundsException.class, () -> buf.setUnsignedByte(8, value)); @@ -3490,8 +3498,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedByteMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x01; buf.setUnsignedByte(0, value); @@ -3510,8 +3518,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfCharMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); char value = 0x0102; @@ -3526,8 +3534,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfCharMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -3544,8 +3552,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfCharMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); char value = 0x0102; @@ -3561,8 +3569,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfCharReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); char value = 0x0102; @@ -3578,8 +3586,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfCharMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getChar(-1)); } } @@ -3587,8 +3595,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfCharReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getChar(-1)); } } @@ -3596,8 +3604,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfCharMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { char value = 0x0102; buf.writeChar(value); assertEquals(value, buf.getChar(0)); @@ -3607,8 +3615,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfCharMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); char value = 0x0102; buf.writeChar(value); @@ -3620,8 +3628,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfCharMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { char value = 0x0102; buf.writeChar(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getChar(1)); @@ -3631,8 +3639,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfCharReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { char value = 0x0102; buf.writeChar(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getChar(1)); @@ -3642,8 +3650,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfCharMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getChar(0)); } } @@ -3651,8 +3659,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfCharReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getChar(0)); } } @@ -3660,8 +3668,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfCharMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(7); char value = 0x0102; @@ -3675,8 +3683,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfCharMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); char value = 0x0102; buf.writeChar(value); @@ -3695,8 +3703,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfCharMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); char value = 0x0102; assertThrows(IndexOutOfBoundsException.class, () -> buf.setChar(-1, value)); @@ -3709,8 +3717,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfCharMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); char value = 0x0102; assertThrows(IndexOutOfBoundsException.class, () -> buf.setChar(7, value)); @@ -3723,8 +3731,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfCharMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); char value = 0x0102; buf.setChar(0, value); @@ -3743,8 +3751,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfShortMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); short value = 0x0102; @@ -3759,8 +3767,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfShortMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -3777,8 +3785,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfShortMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); short value = 0x0102; @@ -3794,8 +3802,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfShortReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); short value = 0x0102; @@ -3811,8 +3819,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfShortMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getShort(-1)); } } @@ -3820,8 +3828,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfShortReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getShort(-1)); } } @@ -3829,8 +3837,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfShortMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { short value = 0x0102; buf.writeShort(value); assertEquals(value, buf.getShort(0)); @@ -3840,8 +3848,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfShortMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); short value = 0x0102; buf.writeShort(value); @@ -3853,8 +3861,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfShortMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { short value = 0x0102; buf.writeShort(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getShort(1)); @@ -3864,8 +3872,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfShortReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { short value = 0x0102; buf.writeShort(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getShort(1)); @@ -3875,8 +3883,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfShortMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getShort(0)); } } @@ -3884,8 +3892,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfShortReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getShort(0)); } } @@ -3893,8 +3901,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedShortMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x0102; @@ -3909,8 +3917,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedShortMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -3927,8 +3935,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedShortMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x0102; @@ -3944,8 +3952,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedShortReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x0102; @@ -3961,8 +3969,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedShortMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedShort(-1)); } } @@ -3970,8 +3978,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedShortReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedShort(-1)); } } @@ -3979,8 +3987,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedShortMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x0102; buf.writeUnsignedShort(value); assertEquals(value, buf.getUnsignedShort(0)); @@ -3990,8 +3998,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedShortMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x0102; buf.writeUnsignedShort(value); @@ -4003,8 +4011,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedShortMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x0102; buf.writeUnsignedShort(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedShort(1)); @@ -4015,8 +4023,8 @@ public class BufTest { @MethodSource("allocators") void offsettedGetOfUnsignedShortReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x0102; buf.writeUnsignedShort(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedShort(1)); @@ -4026,8 +4034,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedShortMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedShort(0)); } } @@ -4035,8 +4043,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedShortReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedShort(0)); } } @@ -4044,8 +4052,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfShortMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(7); short value = 0x0102; @@ -4059,8 +4067,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfShortMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); short value = 0x0102; buf.writeShort(value); @@ -4079,8 +4087,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfShortMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); short value = 0x0102; assertThrows(IndexOutOfBoundsException.class, () -> buf.setShort(-1, value)); @@ -4093,8 +4101,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfShortMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); short value = 0x0102; assertThrows(IndexOutOfBoundsException.class, () -> buf.setShort(7, value)); @@ -4107,8 +4115,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfShortMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); short value = 0x0102; buf.setShort(0, value); @@ -4127,8 +4135,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfUnsignedShortMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(7); int value = 0x0102; @@ -4142,8 +4150,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfUnsignedShortMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x0102; buf.writeUnsignedShort(value); @@ -4162,8 +4170,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedShortMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x0102; assertThrows(IndexOutOfBoundsException.class, () -> buf.setUnsignedShort(-1, value)); @@ -4176,8 +4184,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedShortMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x0102; assertThrows(IndexOutOfBoundsException.class, () -> buf.setUnsignedShort(7, value)); @@ -4190,8 +4198,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedShortMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x0102; buf.setUnsignedShort(0, value); @@ -4210,8 +4218,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x010203; @@ -4226,8 +4234,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfMediumMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -4244,8 +4252,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfMediumMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x010203; @@ -4261,8 +4269,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfMediumReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x010203; @@ -4278,8 +4286,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfMediumMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getMedium(-1)); } } @@ -4287,8 +4295,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfMediumReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getMedium(-1)); } } @@ -4296,8 +4304,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeMedium(value); assertEquals(value, buf.getMedium(0)); @@ -4307,8 +4315,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfMediumMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x010203; buf.writeMedium(value); @@ -4320,8 +4328,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfMediumMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeMedium(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getMedium(1)); @@ -4331,8 +4339,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfMediumReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeMedium(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getMedium(1)); @@ -4342,8 +4350,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfMediumMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getMedium(0)); } } @@ -4351,8 +4359,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfMediumReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getMedium(0)); } } @@ -4360,8 +4368,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x010203; @@ -4376,8 +4384,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedMediumMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -4394,8 +4402,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedMediumMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x010203; @@ -4411,8 +4419,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedMediumReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x010203; @@ -4428,8 +4436,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedMediumMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedMedium(-1)); } } @@ -4437,8 +4445,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedMediumReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedMedium(-1)); } } @@ -4446,8 +4454,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeUnsignedMedium(value); assertEquals(value, buf.getUnsignedMedium(0)); @@ -4457,8 +4465,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedMediumMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x010203; buf.writeUnsignedMedium(value); @@ -4470,8 +4478,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedMediumMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeUnsignedMedium(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedMedium(1)); @@ -4482,8 +4490,8 @@ public class BufTest { @MethodSource("allocators") void offsettedGetOfUnsignedMediumReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeUnsignedMedium(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedMedium(1)); @@ -4493,8 +4501,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedMediumMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedMedium(0)); } } @@ -4502,8 +4510,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedMediumReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedMedium(0)); } } @@ -4511,8 +4519,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfMediumMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(6); int value = 0x010203; @@ -4526,8 +4534,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfMediumMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x010203; buf.writeMedium(value); @@ -4546,8 +4554,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfMediumMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x010203; assertThrows(IndexOutOfBoundsException.class, () -> buf.setMedium(-1, value)); @@ -4560,8 +4568,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfMediumMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x010203; assertThrows(IndexOutOfBoundsException.class, () -> buf.setMedium(6, value)); @@ -4574,8 +4582,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfMediumMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x010203; buf.setMedium(0, value); @@ -4594,8 +4602,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfUnsignedMediumMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(6); int value = 0x010203; @@ -4609,8 +4617,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfUnsignedMediumMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x010203; buf.writeUnsignedMedium(value); @@ -4629,8 +4637,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedMediumMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x010203; assertThrows(IndexOutOfBoundsException.class, () -> buf.setUnsignedMedium(-1, value)); @@ -4643,8 +4651,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedMediumMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x010203; assertThrows(IndexOutOfBoundsException.class, () -> buf.setUnsignedMedium(6, value)); @@ -4657,8 +4665,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedMediumMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x010203; buf.setUnsignedMedium(0, value); @@ -4677,8 +4685,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfIntMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x01020304; @@ -4693,8 +4701,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfIntMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -4711,8 +4719,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfIntMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x01020304; @@ -4728,8 +4736,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfIntReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); int value = 0x01020304; @@ -4745,8 +4753,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfIntMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getInt(-1)); } } @@ -4754,8 +4762,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfIntReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getInt(-1)); } } @@ -4763,8 +4771,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfIntMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x01020304; buf.writeInt(value); assertEquals(value, buf.getInt(0)); @@ -4774,8 +4782,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfIntMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x01020304; buf.writeInt(value); @@ -4787,8 +4795,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfIntMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x01020304; buf.writeInt(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getInt(-1)); @@ -4798,8 +4806,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfIntReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { int value = 0x01020304; buf.writeInt(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getInt(-1)); @@ -4809,8 +4817,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfIntMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getInt(0)); } } @@ -4818,8 +4826,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfIntReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getInt(0)); } } @@ -4827,8 +4835,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedIntMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); long value = 0x01020304; @@ -4843,8 +4851,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedIntMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -4861,8 +4869,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedIntMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); long value = 0x01020304; @@ -4878,8 +4886,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfUnsignedIntReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); long value = 0x01020304; @@ -4895,8 +4903,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedIntMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedInt(-1)); } } @@ -4904,8 +4912,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedIntReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedInt(-1)); } } @@ -4913,8 +4921,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedIntMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { long value = 0x01020304; buf.writeUnsignedInt(value); assertEquals(value, buf.getUnsignedInt(0)); @@ -4924,8 +4932,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedIntMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); long value = 0x01020304; buf.writeUnsignedInt(value); @@ -4937,8 +4945,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedIntMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { long value = 0x01020304; buf.writeUnsignedInt(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedInt(1)); @@ -4949,8 +4957,8 @@ public class BufTest { @MethodSource("allocators") void offsettedGetOfUnsignedIntReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { long value = 0x01020304; buf.writeUnsignedInt(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedInt(1)); @@ -4960,8 +4968,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedIntMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedInt(0)); } } @@ -4969,8 +4977,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfUnsignedIntReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedInt(0)); } } @@ -4978,8 +4986,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfIntMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(5); int value = 0x01020304; @@ -4993,8 +5001,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfIntMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x01020304; buf.writeInt(value); @@ -5013,8 +5021,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfIntMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x01020304; assertThrows(IndexOutOfBoundsException.class, () -> buf.setInt(-1, value)); @@ -5027,8 +5035,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfIntMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); int value = 0x01020304; assertThrows(IndexOutOfBoundsException.class, () -> buf.setInt(5, value)); @@ -5041,8 +5049,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfIntMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); int value = 0x01020304; buf.setInt(0, value); @@ -5061,8 +5069,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfUnsignedIntMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(5); long value = 0x01020304; @@ -5076,8 +5084,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfUnsignedIntMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); long value = 0x01020304; buf.writeUnsignedInt(value); @@ -5096,8 +5104,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedIntMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); long value = 0x01020304; assertThrows(IndexOutOfBoundsException.class, () -> buf.setUnsignedInt(-1, value)); @@ -5110,8 +5118,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedIntMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); long value = 0x01020304; assertThrows(IndexOutOfBoundsException.class, () -> buf.setUnsignedInt(5, value)); @@ -5124,8 +5132,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfUnsignedIntMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); long value = 0x01020304; buf.setUnsignedInt(0, value); @@ -5144,8 +5152,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfFloatMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); float value = Float.intBitsToFloat(0x01020304); @@ -5160,8 +5168,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfFloatMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -5178,8 +5186,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfFloatMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); float value = Float.intBitsToFloat(0x01020304); @@ -5195,8 +5203,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfFloatReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); float value = Float.intBitsToFloat(0x01020304); @@ -5212,8 +5220,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfFloatMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getFloat(-1)); } } @@ -5221,8 +5229,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfFloatReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getFloat(-1)); } } @@ -5230,8 +5238,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfFloatMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { float value = Float.intBitsToFloat(0x01020304); buf.writeFloat(value); assertEquals(value, buf.getFloat(0)); @@ -5241,8 +5249,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfFloatMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); float value = Float.intBitsToFloat(0x01020304); buf.writeFloat(value); @@ -5254,8 +5262,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfFloatMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { float value = Float.intBitsToFloat(0x01020304); buf.writeFloat(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getFloat(1)); @@ -5265,8 +5273,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfFloatReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { float value = Float.intBitsToFloat(0x01020304); buf.writeFloat(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getFloat(1)); @@ -5276,8 +5284,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfFloatMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getFloat(0)); } } @@ -5285,8 +5293,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfFloatReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getFloat(0)); } } @@ -5294,8 +5302,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfFloatMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(5); float value = Float.intBitsToFloat(0x01020304); @@ -5309,8 +5317,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfFloatMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); float value = Float.intBitsToFloat(0x01020304); buf.writeFloat(value); @@ -5329,8 +5337,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfFloatMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); float value = Float.intBitsToFloat(0x01020304); assertThrows(IndexOutOfBoundsException.class, () -> buf.setFloat(-1, value)); @@ -5343,8 +5351,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfFloatMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); float value = Float.intBitsToFloat(0x01020304); assertThrows(IndexOutOfBoundsException.class, () -> buf.setFloat(5, value)); @@ -5357,8 +5365,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfFloatMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); float value = Float.intBitsToFloat(0x01020304); buf.setFloat(0, value); @@ -5377,8 +5385,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfLongMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); long value = 0x0102030405060708L; @@ -5393,8 +5401,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfLongMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -5411,8 +5419,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfLongMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); long value = 0x0102030405060708L; @@ -5428,8 +5436,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfLongReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); long value = 0x0102030405060708L; @@ -5445,8 +5453,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfLongMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getLong(-1)); } } @@ -5454,8 +5462,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfLongReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getLong(-1)); } } @@ -5463,8 +5471,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfLongMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { long value = 0x0102030405060708L; buf.writeLong(value); assertEquals(value, buf.getLong(0)); @@ -5474,8 +5482,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfLongMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); long value = 0x0102030405060708L; buf.writeLong(value); @@ -5487,8 +5495,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfLongMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { long value = 0x0102030405060708L; buf.writeLong(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getLong(1)); @@ -5498,8 +5506,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfLongReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { long value = 0x0102030405060708L; buf.writeLong(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getLong(1)); @@ -5509,8 +5517,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfLongMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getLong(0)); } } @@ -5518,8 +5526,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfLongReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getLong(0)); } } @@ -5527,8 +5535,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfLongMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(1); long value = 0x0102030405060708L; @@ -5542,8 +5550,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfLongMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); long value = 0x0102030405060708L; buf.writeLong(value); @@ -5562,8 +5570,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfLongMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); long value = 0x0102030405060708L; assertThrows(IndexOutOfBoundsException.class, () -> buf.setLong(-1, value)); @@ -5576,8 +5584,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfLongMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); long value = 0x0102030405060708L; assertThrows(IndexOutOfBoundsException.class, () -> buf.setLong(1, value)); @@ -5590,8 +5598,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfLongMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); long value = 0x0102030405060708L; buf.setLong(0, value); @@ -5610,8 +5618,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfDoubleMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); double value = Double.longBitsToDouble(0x0102030405060708L); @@ -5626,8 +5634,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfDoubleMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); @@ -5644,8 +5652,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfDoubleMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); double value = Double.longBitsToDouble(0x0102030405060708L); @@ -5661,8 +5669,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeReadOfDoubleReadOnllyMustBoundsCheckWhenReadOffsetAndSizeIsBeyondWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(0, buf.readableBytes()); assertEquals(Long.BYTES, buf.writableBytes()); double value = Double.longBitsToDouble(0x0102030405060708L); @@ -5678,8 +5686,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfDoubleMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getDouble(-1)); } } @@ -5687,8 +5695,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfDoubleReadOnlyMustBoundsCheckOnNegativeOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getDouble(-1)); } } @@ -5696,8 +5704,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfDoubleMustNotBoundsCheckWhenReadOffsetAndSizeIsEqualToWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { double value = Double.longBitsToDouble(0x0102030405060708L); buf.writeDouble(value); assertEquals(value, buf.getDouble(0)); @@ -5707,8 +5715,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfDoubleMustReadWithDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); double value = Double.longBitsToDouble(0x0102030405060708L); buf.writeDouble(value); @@ -5720,8 +5728,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfDoubleMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { double value = Double.longBitsToDouble(0x0102030405060708L); buf.writeDouble(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.getDouble(1)); @@ -5731,8 +5739,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfDoubleReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { double value = Double.longBitsToDouble(0x0102030405060708L); buf.writeDouble(value); assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getDouble(1)); @@ -5742,8 +5750,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfDoubleMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.getDouble(0)); } } @@ -5751,8 +5759,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedGetOfDoubleReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getDouble(0)); } } @@ -5760,8 +5768,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfDoubleMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); buf.writerOffset(1); double value = Double.longBitsToDouble(0x0102030405060708L); @@ -5775,8 +5783,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void relativeWriteOfDoubleMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); double value = Double.longBitsToDouble(0x0102030405060708L); buf.writeDouble(value); @@ -5795,8 +5803,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfDoubleMustBoundsCheckWhenWriteOffsetIsNegative(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); double value = Double.longBitsToDouble(0x0102030405060708L); assertThrows(IndexOutOfBoundsException.class, () -> buf.setDouble(-1, value)); @@ -5809,8 +5817,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfDoubleMustBoundsCheckWhenWriteOffsetAndSizeIsBeyondCapacity(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { assertEquals(Long.BYTES, buf.capacity()); double value = Double.longBitsToDouble(0x0102030405060708L); assertThrows(IndexOutOfBoundsException.class, () -> buf.setDouble(1, value)); @@ -5823,8 +5831,8 @@ public class BufTest { @ParameterizedTest @MethodSource("allocators") void offsettedSetOfDoubleMustHaveDefaultEndianByteOrder(Fixture fixture) { - try (Allocator allocator = fixture.createAllocator(); - Buf buf = allocator.allocate(8)) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { buf.order(BIG_ENDIAN); double value = Double.longBitsToDouble(0x0102030405060708L); buf.setDouble(0, value); @@ -5841,7 +5849,7 @@ public class BufTest { } // - private static byte[] toByteArray(Buf buf) { + private static byte[] toByteArray(Buffer buf) { byte[] bs = new byte[buf.capacity()]; buf.copyInto(0, bs, 0, bs.length); return bs; diff --git a/src/test/java/io/netty/buffer/api/Fixture.java b/src/test/java/io/netty/buffer/api/Fixture.java index 9bcf4ad..9bd800c 100644 --- a/src/test/java/io/netty/buffer/api/Fixture.java +++ b/src/test/java/io/netty/buffer/api/Fixture.java @@ -19,23 +19,23 @@ import java.util.Arrays; import java.util.EnumSet; import java.util.function.Supplier; -public final class Fixture implements Supplier { +public final class Fixture implements Supplier { private final String name; - private final Supplier factory; + private final Supplier factory; private final EnumSet properties; - public Fixture(String name, Supplier factory, Properties... props) { + public Fixture(String name, Supplier factory, Properties... props) { this.name = name; this.factory = factory; properties = EnumSet.copyOf(Arrays.asList(props)); } - public Allocator createAllocator() { + public BufferAllocator createAllocator() { return factory.get(); } @Override - public Allocator get() { + public BufferAllocator get() { return factory.get(); } diff --git a/src/test/java/io/netty/buffer/api/benchmarks/ByteIterationBenchmark.java b/src/test/java/io/netty/buffer/api/benchmarks/ByteIterationBenchmark.java index ba3a38f..deea3cf 100644 --- a/src/test/java/io/netty/buffer/api/benchmarks/ByteIterationBenchmark.java +++ b/src/test/java/io/netty/buffer/api/benchmarks/ByteIterationBenchmark.java @@ -15,8 +15,8 @@ */ package io.netty.buffer.api.benchmarks; -import io.netty.buffer.api.Allocator; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.BufferAllocator; +import io.netty.buffer.api.Buffer; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; @@ -44,29 +44,29 @@ public class ByteIterationBenchmark { @Param({"heap", "direct", "composite-heap", "composite-direct"}) public String type; - Allocator allocator; - private Buf buf; + BufferAllocator allocator; + private Buffer buf; @Setup public void setUp() { switch (type) { case "heap": - allocator = Allocator.heap(); + allocator = BufferAllocator.heap(); buf = allocator.allocate(SIZE); break; case "direct": - allocator = Allocator.direct(); + allocator = BufferAllocator.direct(); buf = allocator.allocate(SIZE); break; case "composite-heap": - allocator = Allocator.heap(); + allocator = BufferAllocator.heap(); try (var a = allocator.allocate(SIZE / 2); var b = allocator.allocate(SIZE / 2)) { buf = allocator.compose(a, b); } break; case "composite-direct": - allocator = Allocator.direct(); + allocator = BufferAllocator.direct(); try (var a = allocator.allocate(SIZE / 2); var b = allocator.allocate(SIZE / 2)) { buf = allocator.compose(a, b); diff --git a/src/test/java/io/netty/buffer/api/benchmarks/MemSegBufAccessBenchmark.java b/src/test/java/io/netty/buffer/api/benchmarks/MemSegBufAccessBenchmark.java index b7aa090..757f6bd 100644 --- a/src/test/java/io/netty/buffer/api/benchmarks/MemSegBufAccessBenchmark.java +++ b/src/test/java/io/netty/buffer/api/benchmarks/MemSegBufAccessBenchmark.java @@ -15,8 +15,8 @@ */ package io.netty.buffer.api.benchmarks; -import io.netty.buffer.api.Allocator; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.BufferAllocator; +import io.netty.buffer.api.Buffer; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; @@ -42,30 +42,30 @@ public class MemSegBufAccessBenchmark { public enum BBufType { DIRECT { @Override - Buf newBuffer() { - return Allocator.direct().allocate(64); + Buffer newBuffer() { + return BufferAllocator.direct().allocate(64); } }, HEAP { @Override - Buf newBuffer() { - return Allocator.heap().allocate(64); + Buffer newBuffer() { + return BufferAllocator.heap().allocate(64); } }, // COMPOSITE { // @Override -// Buf newBuffer() { +// Buffer newBuffer() { // return Unpooled.wrappedBuffer(UNSAFE.newBuffer(), HEAP.newBuffer()); // } // }, // NIO { // @Override -// Buf newBuffer() { +// Buffer newBuffer() { // return new NioFacade(BBuffer.allocateDirect(64)); // } // } ; - abstract Buf newBuffer(); + abstract Buffer newBuffer(); } @Param @@ -80,7 +80,7 @@ public class MemSegBufAccessBenchmark { buffer.writerOffset(batchSize); } - private Buf buffer; + private Buffer buffer; @TearDown public void tearDown() { @@ -93,7 +93,7 @@ public class MemSegBufAccessBenchmark { } @Benchmark - public Buf setLong() { + public Buffer setLong() { return buffer.setLong(0, 1); } diff --git a/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java b/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java index 2b50bff..d719840 100644 --- a/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java +++ b/src/test/java/io/netty/buffer/api/benchmarks/MemorySegmentClosedByCleanerBenchmark.java @@ -15,8 +15,8 @@ */ package io.netty.buffer.api.benchmarks; -import io.netty.buffer.api.Allocator; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.BufferAllocator; +import io.netty.buffer.api.Buffer; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; @@ -41,10 +41,10 @@ import static java.util.concurrent.CompletableFuture.completedFuture; @OutputTimeUnit(TimeUnit.MICROSECONDS) @State(Scope.Benchmark) public class MemorySegmentClosedByCleanerBenchmark { - private static final Allocator heap = Allocator.heap(); - private static final Allocator heapPooled = Allocator.pooledHeap(); - private static final Allocator direct = Allocator.direct(); - private static final Allocator directPooled = Allocator.pooledDirect(); + private static final BufferAllocator heap = BufferAllocator.heap(); + private static final BufferAllocator heapPooled = BufferAllocator.pooledHeap(); + private static final BufferAllocator direct = BufferAllocator.direct(); + private static final BufferAllocator directPooled = BufferAllocator.pooledDirect(); @Param({"heavy", "light"}) public String workload; @@ -62,56 +62,56 @@ public class MemorySegmentClosedByCleanerBenchmark { } @Benchmark - public Buf explicitCloseHeap() throws Exception { - try (Buf buf = process(heap.allocate(256))) { + public Buffer explicitCloseHeap() throws Exception { + try (Buffer buf = process(heap.allocate(256))) { return buf; } } @Benchmark - public Buf explicitPooledCloseHeap() throws Exception { - try (Buf buf = process(heapPooled.allocate(256))) { + public Buffer explicitPooledCloseHeap() throws Exception { + try (Buffer buf = process(heapPooled.allocate(256))) { return buf; } } @Benchmark - public Buf explicitCloseDirect() throws Exception { - try (Buf buf = process(direct.allocate(256))) { + public Buffer explicitCloseDirect() throws Exception { + try (Buffer buf = process(direct.allocate(256))) { return buf; } } @Benchmark - public Buf explicitPooledCloseDirect() throws Exception { - try (Buf buf = process(directPooled.allocate(256))) { + public Buffer explicitPooledCloseDirect() throws Exception { + try (Buffer buf = process(directPooled.allocate(256))) { return buf; } } @Benchmark - public Buf cleanerClose() throws Exception { + public Buffer cleanerClose() throws Exception { return process(direct.allocate(256)); } @Benchmark - public Buf cleanerClosePooled() throws Exception { + public Buffer cleanerClosePooled() throws Exception { return process(directPooled.allocate(256)); } - private Buf process(Buf buffer) throws Exception { + private Buffer process(Buffer buffer) throws Exception { // Simulate some async network server thingy, processing the buffer. var tlr = ThreadLocalRandom.current(); if (isHeavy) { return completedFuture(buffer.send()).thenApplyAsync(send -> { - try (Buf buf = send.receive()) { + try (Buffer buf = send.receive()) { while (buf.writableBytes() > 0) { buf.writeByte((byte) tlr.nextInt()); } return buf.send(); } }).thenApplyAsync(send -> { - try (Buf buf = send.receive()) { + try (Buffer buf = send.receive()) { byte b = 0; while (buf.readableBytes() > 0) { b += buf.readByte(); diff --git a/src/test/java/io/netty/buffer/api/benchmarks/SendBenchmark.java b/src/test/java/io/netty/buffer/api/benchmarks/SendBenchmark.java index 432e337..d5c3176 100644 --- a/src/test/java/io/netty/buffer/api/benchmarks/SendBenchmark.java +++ b/src/test/java/io/netty/buffer/api/benchmarks/SendBenchmark.java @@ -15,8 +15,8 @@ */ package io.netty.buffer.api.benchmarks; -import io.netty.buffer.api.Allocator; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.BufferAllocator; +import io.netty.buffer.api.Buffer; import io.netty.buffer.api.Send; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -40,27 +40,27 @@ import static java.util.concurrent.CompletableFuture.completedFuture; @OutputTimeUnit(TimeUnit.MICROSECONDS) @State(Scope.Benchmark) public class SendBenchmark { - private static final Allocator NON_POOLED = Allocator.heap(); - private static final Allocator POOLED = Allocator.pooledHeap(); - private static final Function, Send> BUFFER_BOUNCE = send -> { - try (Buf buf = send.receive()) { + private static final BufferAllocator NON_POOLED = BufferAllocator.heap(); + private static final BufferAllocator POOLED = BufferAllocator.pooledHeap(); + private static final Function, Send> BUFFER_BOUNCE = send -> { + try (Buffer buf = send.receive()) { return buf.send(); } }; @Benchmark - public Buf sendNonPooled() throws Exception { - try (Buf buf = NON_POOLED.allocate(8)) { - try (Buf receive = completedFuture(buf.send()).thenApplyAsync(BUFFER_BOUNCE).get().receive()) { + public Buffer sendNonPooled() throws Exception { + try (Buffer buf = NON_POOLED.allocate(8)) { + try (Buffer receive = completedFuture(buf.send()).thenApplyAsync(BUFFER_BOUNCE).get().receive()) { return receive; } } } @Benchmark - public Buf sendPooled() throws Exception { - try (Buf buf = POOLED.allocate(8)) { - try (Buf receive = completedFuture(buf.send()).thenApplyAsync(BUFFER_BOUNCE).get().receive()) { + public Buffer sendPooled() throws Exception { + try (Buffer buf = POOLED.allocate(8)) { + try (Buffer receive = completedFuture(buf.send()).thenApplyAsync(BUFFER_BOUNCE).get().receive()) { return receive; } } diff --git a/src/test/java/io/netty/buffer/api/examples/AsyncExample.java b/src/test/java/io/netty/buffer/api/examples/AsyncExample.java index 9c5211a..0c8beaa 100644 --- a/src/test/java/io/netty/buffer/api/examples/AsyncExample.java +++ b/src/test/java/io/netty/buffer/api/examples/AsyncExample.java @@ -15,25 +15,25 @@ */ package io.netty.buffer.api.examples; -import io.netty.buffer.api.Allocator; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.BufferAllocator; +import io.netty.buffer.api.Buffer; import static java.lang.System.out; import static java.util.concurrent.CompletableFuture.completedFuture; public final class AsyncExample { public static void main(String[] args) throws Exception { - try (Allocator allocator = Allocator.pooledDirect(); - Buf startBuf = allocator.allocate(16)) { + try (BufferAllocator allocator = BufferAllocator.pooledDirect(); + Buffer startBuf = allocator.allocate(16)) { startBuf.writeLong(threadId()); completedFuture(startBuf.send()).thenApplyAsync(send -> { - try (Buf buf = send.receive()) { + try (Buffer buf = send.receive()) { buf.writeLong(threadId()); return buf.send(); } }).thenAcceptAsync(send -> { - try (Buf buf = send.receive()) { + try (Buffer buf = send.receive()) { out.println("First thread id was " + buf.readLong()); out.println("Then sent to " + buf.readLong()); out.println("And now in thread " + threadId()); diff --git a/src/test/java/io/netty/buffer/api/examples/ComposingAndSlicingExample.java b/src/test/java/io/netty/buffer/api/examples/ComposingAndSlicingExample.java index 1c970aa..f374c2c 100644 --- a/src/test/java/io/netty/buffer/api/examples/ComposingAndSlicingExample.java +++ b/src/test/java/io/netty/buffer/api/examples/ComposingAndSlicingExample.java @@ -15,23 +15,23 @@ */ package io.netty.buffer.api.examples; -import io.netty.buffer.api.Allocator; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.BufferAllocator; +import io.netty.buffer.api.Buffer; import io.netty.buffer.api.Scope; import java.util.concurrent.ThreadLocalRandom; public final class ComposingAndSlicingExample { public static void main(String[] args) { - try (Allocator allocator = Allocator.pooledDirect(); - Buf buf = createBigBuffer(allocator)) { + try (BufferAllocator allocator = BufferAllocator.pooledDirect(); + Buffer buf = createBigBuffer(allocator)) { ThreadLocalRandom tlr = ThreadLocalRandom.current(); for (int i = 0; i < tlr.nextInt(4, 200); i++) { buf.writeByte((byte) tlr.nextInt()); } - try (Buf slice = buf.slice()) { + try (Buffer slice = buf.slice()) { slice.send(); System.out.println("buf.capacity() = " + buf.capacity()); System.out.println("buf.readableBytes() = " + buf.readableBytes()); @@ -42,7 +42,7 @@ public final class ComposingAndSlicingExample { } } - private static Buf createBigBuffer(Allocator allocator) { + private static Buffer createBigBuffer(BufferAllocator allocator) { try (Scope scope = new Scope()) { return allocator.compose( scope.add(allocator.allocate(64)), diff --git a/src/test/java/io/netty/buffer/api/examples/FileCopyExample.java b/src/test/java/io/netty/buffer/api/examples/FileCopyExample.java index 5099416..1dca599 100644 --- a/src/test/java/io/netty/buffer/api/examples/FileCopyExample.java +++ b/src/test/java/io/netty/buffer/api/examples/FileCopyExample.java @@ -15,8 +15,8 @@ */ package io.netty.buffer.api.examples; -import io.netty.buffer.api.Allocator; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.BufferAllocator; +import io.netty.buffer.api.Buffer; import io.netty.buffer.api.Send; import java.nio.channels.FileChannel; @@ -33,15 +33,15 @@ import static java.nio.file.StandardOpenOption.WRITE; public final class FileCopyExample { public static void main(String[] args) throws Exception { ExecutorService executor = Executors.newFixedThreadPool(2); - ArrayBlockingQueue> queue = new ArrayBlockingQueue<>(8); - try (Allocator allocator = Allocator.pooledDirect(); + ArrayBlockingQueue> queue = new ArrayBlockingQueue<>(8); + try (BufferAllocator allocator = BufferAllocator.pooledDirect(); var input = FileChannel.open(Path.of("/dev/urandom"), READ); var output = FileChannel.open(Path.of("random.bin"), CREATE, TRUNCATE_EXISTING, WRITE)) { - Send done = allocator.compose().send(); + Send done = allocator.compose().send(); var reader = executor.submit(() -> { for (int i = 0; i < 1024; i++) { - try (Buf in = allocator.allocate(1024)) { + try (Buffer in = allocator.allocate(1024)) { System.out.println("in = " + in); in.forEachWritable(0, (index, component) -> { var bb = component.writableBuffer(); @@ -59,9 +59,9 @@ public final class FileCopyExample { }); var writer = executor.submit(() -> { - Send send; + Send send; while ((send = queue.take()) != done) { - try (Buf out = send.receive()) { + try (Buffer out = send.receive()) { System.out.println("Received " + out.readableBytes() + " bytes."); out.forEachReadable(0, (index, component) -> { var bb = component.readableBuffer(); diff --git a/src/test/java/io/netty/buffer/api/examples/SendExample.java b/src/test/java/io/netty/buffer/api/examples/SendExample.java index 6e662c7..db3b04a 100644 --- a/src/test/java/io/netty/buffer/api/examples/SendExample.java +++ b/src/test/java/io/netty/buffer/api/examples/SendExample.java @@ -15,8 +15,8 @@ */ package io.netty.buffer.api.examples; -import io.netty.buffer.api.Allocator; -import io.netty.buffer.api.Buf; +import io.netty.buffer.api.BufferAllocator; +import io.netty.buffer.api.Buffer; import io.netty.buffer.api.Send; import java.util.concurrent.ExecutorService; @@ -31,7 +31,7 @@ public class SendExample { public static void main(String[] args) throws Exception { ExecutorService executor = newSingleThreadExecutor(); - Allocator allocator = Allocator.heap(); + BufferAllocator allocator = BufferAllocator.heap(); var future = beginTask(executor, allocator); future.get(); @@ -41,17 +41,17 @@ public class SendExample { } private static Future beginTask( - ExecutorService executor, Allocator allocator) { - try (Buf buf = allocator.allocate(32)) { + ExecutorService executor, BufferAllocator allocator) { + try (Buffer buf = allocator.allocate(32)) { // !!! pit-fall: buffer life-time ends before task completes return executor.submit(new Task(buf)); } } private static class Task implements Runnable { - private final Buf buf; + private final Buffer buf; - Task(Buf buf) { + Task(Buffer buf) { this.buf = buf; } @@ -68,7 +68,7 @@ public class SendExample { static final class Ex2 { public static void main(String[] args) throws Exception { ExecutorService executor = newSingleThreadExecutor(); - Allocator allocator = Allocator.heap(); + BufferAllocator allocator = BufferAllocator.heap(); var future = beginTask(executor, allocator); future.get(); @@ -78,17 +78,17 @@ public class SendExample { } private static Future beginTask( - ExecutorService executor, Allocator allocator) { - try (Buf buf = allocator.allocate(32)) { + ExecutorService executor, BufferAllocator allocator) { + try (Buffer buf = allocator.allocate(32)) { // !!! pit-fall: Rc decrement in other thread. return executor.submit(new Task(buf.acquire())); } } private static class Task implements Runnable { - private final Buf buf; + private final Buffer buf; - Task(Buf buf) { + Task(Buffer buf) { this.buf = buf; } @@ -107,7 +107,7 @@ public class SendExample { static final class Ex3 { public static void main(String[] args) throws Exception { ExecutorService executor = newSingleThreadExecutor(); - Allocator allocator = Allocator.heap(); + BufferAllocator allocator = BufferAllocator.heap(); var future = beginTask(executor, allocator); future.get(); @@ -117,22 +117,22 @@ public class SendExample { } private static Future beginTask( - ExecutorService executor, Allocator allocator) { - try (Buf buf = allocator.allocate(32)) { + ExecutorService executor, BufferAllocator allocator) { + try (Buffer buf = allocator.allocate(32)) { return executor.submit(new Task(buf.send())); } } private static class Task implements Runnable { - private final Send send; + private final Send send; - Task(Send send) { + Task(Send send) { this.send = send; } @Override public void run() { - try (Buf buf = send.receive()) { + try (Buffer buf = send.receive()) { while (buf.writableBytes() > 0) { buf.writeByte((byte) 42); } @@ -144,9 +144,9 @@ public class SendExample { static final class Ex4 { public static void main(String[] args) throws Exception { ExecutorService executor = newFixedThreadPool(4); - Allocator allocator = Allocator.heap(); + BufferAllocator allocator = BufferAllocator.heap(); - try (Buf buf = allocator.allocate(4096)) { + try (Buffer buf = allocator.allocate(4096)) { // !!! pit-fall: Rc decrement in other thread. var futA = executor.submit(new Task(buf.slice(0, 1024))); var futB = executor.submit(new Task(buf.slice(1024, 1024))); @@ -163,9 +163,9 @@ public class SendExample { } private static class Task implements Runnable { - private final Buf slice; + private final Buffer slice; - Task(Buf slice) { + Task(Buffer slice) { this.slice = slice; } @@ -183,13 +183,13 @@ public class SendExample { static final class Ex5 { public static void main(String[] args) throws Exception { ExecutorService executor = newFixedThreadPool(4); - Allocator allocator = Allocator.heap(); + BufferAllocator allocator = BufferAllocator.heap(); - try (Buf buf = allocator.allocate(4096); - Buf sliceA = buf.slice(0, 1024); - Buf sliceB = buf.slice(1024, 1024); - Buf sliceC = buf.slice(2048, 1024); - Buf sliceD = buf.slice(3072, 1024)) { + try (Buffer buf = allocator.allocate(4096); + Buffer sliceA = buf.slice(0, 1024); + Buffer sliceB = buf.slice(1024, 1024); + Buffer sliceC = buf.slice(2048, 1024); + Buffer sliceD = buf.slice(3072, 1024)) { var futA = executor.submit(new Task(sliceA)); var futB = executor.submit(new Task(sliceB)); var futC = executor.submit(new Task(sliceC)); @@ -205,9 +205,9 @@ public class SendExample { } private static class Task implements Runnable { - private final Buf slice; + private final Buffer slice; - Task(Buf slice) { + Task(Buffer slice) { this.slice = slice; } @@ -223,9 +223,9 @@ public class SendExample { static final class Ex6 { public static void main(String[] args) throws Exception { ExecutorService executor = newFixedThreadPool(4); - Allocator allocator = Allocator.heap(); + BufferAllocator allocator = BufferAllocator.heap(); - try (Buf buf = allocator.allocate(4096)) { + try (Buffer buf = allocator.allocate(4096)) { var futA = executor.submit(new Task(buf.writerOffset(1024).bifurcate().send())); var futB = executor.submit(new Task(buf.writerOffset(1024).bifurcate().send())); var futC = executor.submit(new Task(buf.writerOffset(1024).bifurcate().send())); @@ -241,15 +241,15 @@ public class SendExample { } private static class Task implements Runnable { - private final Send send; + private final Send send; - Task(Send send) { + Task(Send send) { this.send = send; } @Override public void run() { - try (Buf buf = send.receive().writerOffset(0)) { + try (Buffer buf = send.receive().writerOffset(0)) { while (buf.writableBytes() > 0) { buf.writeByte((byte) 42); }