Package io.netty.buffer
Class AbstractByteBufAllocator
java.lang.Object
io.netty.buffer.AbstractByteBufAllocator
- All Implemented Interfaces:
ByteBufAllocator
- Direct Known Subclasses:
PooledByteBufAllocator
,UnpooledByteBufAllocator
Skeletal
ByteBufAllocator
implementation to extend.-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
private final boolean
private final ByteBuf
Fields inherited from interface io.netty.buffer.ByteBufAllocator
DEFAULT
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Instance use heap buffers by defaultprotected
AbstractByteBufAllocator
(boolean preferDirect) Create new instance -
Method Summary
Modifier and TypeMethodDescriptionbuffer()
Allocate aByteBuf
.buffer
(int initialCapacity) Allocate aByteBuf
with the given initial capacity.buffer
(int initialCapacity, int maxCapacity) Allocate aByteBuf
with the given initial capacity and the given maximal capacity.int
calculateNewCapacity
(int minNewCapacity, int maxCapacity) Allocate aCompositeByteBuf
.compositeBuffer
(int maxNumComponents) Allocate aCompositeByteBuf
with the given maximum number of components that can be stored in it.Allocate a directCompositeByteBuf
.compositeDirectBuffer
(int maxNumComponents) Allocate a directCompositeByteBuf
with the given maximum number of components that can be stored in it.Allocate a heapCompositeByteBuf
.compositeHeapBuffer
(int maxNumComponents) Allocate a heapCompositeByteBuf
with the given maximum number of components that can be stored in it.Allocate a directByteBuf
.directBuffer
(int initialCapacity) Allocate a directByteBuf
with the given initial capacity.directBuffer
(int initialCapacity, int maxCapacity) Allocate a directByteBuf
with the given initial capacity and the given maximal capacity.Allocate a heapByteBuf
.heapBuffer
(int initialCapacity) Allocate a heapByteBuf
with the given initial capacity.heapBuffer
(int initialCapacity, int maxCapacity) Allocate a heapByteBuf
with the given initial capacity and the given maximal capacity.ioBuffer()
Allocate aByteBuf
, preferably a direct buffer which is suitable for I/O.ioBuffer
(int initialCapacity) Allocate aByteBuf
, preferably a direct buffer which is suitable for I/O.ioBuffer
(int initialCapacity, int maxCapacity) Allocate aByteBuf
, preferably a direct buffer which is suitable for I/O.protected abstract ByteBuf
newDirectBuffer
(int initialCapacity, int maxCapacity) Create a directByteBuf
with the given initialCapacity and maxCapacity.protected abstract ByteBuf
newHeapBuffer
(int initialCapacity, int maxCapacity) Create a heapByteBuf
with the given initialCapacity and maxCapacity.protected static ByteBuf
toLeakAwareBuffer
(ByteBuf buf) protected static CompositeByteBuf
toString()
private static void
validate
(int initialCapacity, int maxCapacity) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.netty.buffer.ByteBufAllocator
isDirectBufferPooled
-
Field Details
-
DEFAULT_INITIAL_CAPACITY
static final int DEFAULT_INITIAL_CAPACITY- See Also:
-
DEFAULT_MAX_CAPACITY
static final int DEFAULT_MAX_CAPACITY- See Also:
-
DEFAULT_MAX_COMPONENTS
static final int DEFAULT_MAX_COMPONENTS- See Also:
-
CALCULATE_THRESHOLD
static final int CALCULATE_THRESHOLD- See Also:
-
directByDefault
private final boolean directByDefault -
emptyBuf
-
-
Constructor Details
-
AbstractByteBufAllocator
protected AbstractByteBufAllocator()Instance use heap buffers by default -
AbstractByteBufAllocator
protected AbstractByteBufAllocator(boolean preferDirect) Create new instance- Parameters:
preferDirect
-true
ifbuffer(int)
should try to allocate a direct buffer rather than a heap buffer
-
-
Method Details
-
toLeakAwareBuffer
-
toLeakAwareBuffer
-
buffer
Description copied from interface:ByteBufAllocator
Allocate aByteBuf
. If it is a direct or heap buffer depends on the actual implementation.- Specified by:
buffer
in interfaceByteBufAllocator
-
buffer
Description copied from interface:ByteBufAllocator
Allocate aByteBuf
with the given initial capacity. If it is a direct or heap buffer depends on the actual implementation.- Specified by:
buffer
in interfaceByteBufAllocator
-
buffer
Description copied from interface:ByteBufAllocator
Allocate aByteBuf
with the given initial capacity and the given maximal capacity. If it is a direct or heap buffer depends on the actual implementation.- Specified by:
buffer
in interfaceByteBufAllocator
-
ioBuffer
Description copied from interface:ByteBufAllocator
Allocate aByteBuf
, preferably a direct buffer which is suitable for I/O.- Specified by:
ioBuffer
in interfaceByteBufAllocator
-
ioBuffer
Description copied from interface:ByteBufAllocator
Allocate aByteBuf
, preferably a direct buffer which is suitable for I/O.- Specified by:
ioBuffer
in interfaceByteBufAllocator
-
ioBuffer
Description copied from interface:ByteBufAllocator
Allocate aByteBuf
, preferably a direct buffer which is suitable for I/O.- Specified by:
ioBuffer
in interfaceByteBufAllocator
-
heapBuffer
Description copied from interface:ByteBufAllocator
Allocate a heapByteBuf
.- Specified by:
heapBuffer
in interfaceByteBufAllocator
-
heapBuffer
Description copied from interface:ByteBufAllocator
Allocate a heapByteBuf
with the given initial capacity.- Specified by:
heapBuffer
in interfaceByteBufAllocator
-
heapBuffer
Description copied from interface:ByteBufAllocator
Allocate a heapByteBuf
with the given initial capacity and the given maximal capacity.- Specified by:
heapBuffer
in interfaceByteBufAllocator
-
directBuffer
Description copied from interface:ByteBufAllocator
Allocate a directByteBuf
.- Specified by:
directBuffer
in interfaceByteBufAllocator
-
directBuffer
Description copied from interface:ByteBufAllocator
Allocate a directByteBuf
with the given initial capacity.- Specified by:
directBuffer
in interfaceByteBufAllocator
-
directBuffer
Description copied from interface:ByteBufAllocator
Allocate a directByteBuf
with the given initial capacity and the given maximal capacity.- Specified by:
directBuffer
in interfaceByteBufAllocator
-
compositeBuffer
Description copied from interface:ByteBufAllocator
Allocate aCompositeByteBuf
. If it is a direct or heap buffer depends on the actual implementation.- Specified by:
compositeBuffer
in interfaceByteBufAllocator
-
compositeBuffer
Description copied from interface:ByteBufAllocator
Allocate aCompositeByteBuf
with the given maximum number of components that can be stored in it. If it is a direct or heap buffer depends on the actual implementation.- Specified by:
compositeBuffer
in interfaceByteBufAllocator
-
compositeHeapBuffer
Description copied from interface:ByteBufAllocator
Allocate a heapCompositeByteBuf
.- Specified by:
compositeHeapBuffer
in interfaceByteBufAllocator
-
compositeHeapBuffer
Description copied from interface:ByteBufAllocator
Allocate a heapCompositeByteBuf
with the given maximum number of components that can be stored in it.- Specified by:
compositeHeapBuffer
in interfaceByteBufAllocator
-
compositeDirectBuffer
Description copied from interface:ByteBufAllocator
Allocate a directCompositeByteBuf
.- Specified by:
compositeDirectBuffer
in interfaceByteBufAllocator
-
compositeDirectBuffer
Description copied from interface:ByteBufAllocator
Allocate a directCompositeByteBuf
with the given maximum number of components that can be stored in it.- Specified by:
compositeDirectBuffer
in interfaceByteBufAllocator
-
validate
private static void validate(int initialCapacity, int maxCapacity) -
newHeapBuffer
Create a heapByteBuf
with the given initialCapacity and maxCapacity. -
newDirectBuffer
Create a directByteBuf
with the given initialCapacity and maxCapacity. -
toString
-
calculateNewCapacity
public int calculateNewCapacity(int minNewCapacity, int maxCapacity) Description copied from interface:ByteBufAllocator
Calculate the new capacity of aByteBuf
that is used when aByteBuf
needs to expand by theminNewCapacity
withmaxCapacity
as upper-bound.- Specified by:
calculateNewCapacity
in interfaceByteBufAllocator
-