Package io.netty.buffer
Class DefaultByteBufHolder
- java.lang.Object
-
- io.netty.buffer.DefaultByteBufHolder
-
- All Implemented Interfaces:
ByteBufHolder
,ReferenceCounted
- Direct Known Subclasses:
DefaultBulkStringRedisContent
,DefaultHttp2GoAwayFrame
,DefaultHttp2UnknownFrame
,DefaultSmtpContent
,DefaultSpdyUnknownFrame
,DefaultStompContentSubframe
,FullBulkStringRedisMessage
,HAProxyTLV
,SctpMessage
,UdtMessage
,WebSocketFrame
public class DefaultByteBufHolder extends java.lang.Object implements ByteBufHolder
Default implementation of aByteBufHolder
that holds it's data in aByteBuf
.
-
-
Constructor Summary
Constructors Constructor Description DefaultByteBufHolder(ByteBuf data)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteBuf
content()
Return the data which is held by thisByteBufHolder
.protected java.lang.String
contentToString()
ReturnByteBuf.toString()
without checking the reference count first.ByteBufHolder
copy()
Creates a deep copy of thisByteBufHolder
.ByteBufHolder
duplicate()
Duplicates thisByteBufHolder
.boolean
equals(java.lang.Object o)
This implementation of theequals
operation is restricted to work only with instances of the same class.int
hashCode()
int
refCnt()
Returns the reference count of this object.boolean
release()
Decreases the reference count by1
and deallocates this object if the reference count reaches at0
.boolean
release(int decrement)
Decreases the reference count by the specifieddecrement
and deallocates this object if the reference count reaches at0
.ByteBufHolder
replace(ByteBuf content)
Returns a newByteBufHolder
which contains the specifiedcontent
.ByteBufHolder
retain()
Increases the reference count by1
.ByteBufHolder
retain(int increment)
Increases the reference count by the specifiedincrement
.ByteBufHolder
retainedDuplicate()
Duplicates thisByteBufHolder
.java.lang.String
toString()
ByteBufHolder
touch()
Records the current access location of this object for debugging purposes.ByteBufHolder
touch(java.lang.Object hint)
Records the current access location of this object with an additional arbitrary information for debugging purposes.
-
-
-
Constructor Detail
-
DefaultByteBufHolder
public DefaultByteBufHolder(ByteBuf data)
-
-
Method Detail
-
content
public ByteBuf content()
Description copied from interface:ByteBufHolder
Return the data which is held by thisByteBufHolder
.- Specified by:
content
in interfaceByteBufHolder
-
copy
public ByteBufHolder copy()
Creates a deep copy of thisByteBufHolder
.This method calls
replace(content().copy())
by default.- Specified by:
copy
in interfaceByteBufHolder
-
duplicate
public ByteBufHolder duplicate()
Duplicates thisByteBufHolder
. Be aware that this will not automatically callByteBufHolder.retain()
.This method calls
replace(content().duplicate())
by default.- Specified by:
duplicate
in interfaceByteBufHolder
-
retainedDuplicate
public ByteBufHolder retainedDuplicate()
Duplicates thisByteBufHolder
. This method returns a retained duplicate unlikeByteBufHolder.duplicate()
.This method calls
replace(content().retainedDuplicate())
by default.- Specified by:
retainedDuplicate
in interfaceByteBufHolder
- See Also:
ByteBuf.retainedDuplicate()
-
replace
public ByteBufHolder replace(ByteBuf content)
Returns a newByteBufHolder
which contains the specifiedcontent
.Override this method to return a new instance of this object whose content is set to the specified
content
. The default implementation ofcopy()
,duplicate()
andretainedDuplicate()
invokes this method to create a copy.- Specified by:
replace
in interfaceByteBufHolder
-
refCnt
public int refCnt()
Description copied from interface:ReferenceCounted
Returns the reference count of this object. If0
, it means this object has been deallocated.- Specified by:
refCnt
in interfaceReferenceCounted
-
retain
public ByteBufHolder retain()
Description copied from interface:ReferenceCounted
Increases the reference count by1
.- Specified by:
retain
in interfaceByteBufHolder
- Specified by:
retain
in interfaceReferenceCounted
-
retain
public ByteBufHolder retain(int increment)
Description copied from interface:ReferenceCounted
Increases the reference count by the specifiedincrement
.- Specified by:
retain
in interfaceByteBufHolder
- Specified by:
retain
in interfaceReferenceCounted
-
touch
public ByteBufHolder touch()
Description copied from interface:ReferenceCounted
Records the current access location of this object for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you viaResourceLeakDetector
. This method is a shortcut totouch(null)
.- Specified by:
touch
in interfaceByteBufHolder
- Specified by:
touch
in interfaceReferenceCounted
-
touch
public ByteBufHolder touch(java.lang.Object hint)
Description copied from interface:ReferenceCounted
Records the current access location of this object with an additional arbitrary information for debugging purposes. If this object is determined to be leaked, the information recorded by this operation will be provided to you viaResourceLeakDetector
.- Specified by:
touch
in interfaceByteBufHolder
- Specified by:
touch
in interfaceReferenceCounted
-
release
public boolean release()
Description copied from interface:ReferenceCounted
Decreases the reference count by1
and deallocates this object if the reference count reaches at0
.- Specified by:
release
in interfaceReferenceCounted
- Returns:
true
if and only if the reference count became0
and this object has been deallocated
-
release
public boolean release(int decrement)
Description copied from interface:ReferenceCounted
Decreases the reference count by the specifieddecrement
and deallocates this object if the reference count reaches at0
.- Specified by:
release
in interfaceReferenceCounted
- Returns:
true
if and only if the reference count became0
and this object has been deallocated
-
contentToString
protected final java.lang.String contentToString()
ReturnByteBuf.toString()
without checking the reference count first. This is useful to implementtoString()
.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
This implementation of theequals
operation is restricted to work only with instances of the same class. The reason for that is that Netty library already has a number of classes that extendDefaultByteBufHolder
and overrideequals
method with an additional comparison logic and we need the symmetric property of theequals
operation to be preserved.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- the reference object with which to compare.- Returns:
true
if this object is the same as the obj argument;false
otherwise.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-