Java Utililty Methods ByteBuffer Clean

List of utility methods to do ByteBuffer Clean

Description

The list of methods to do ByteBuffer Clean are organized into topic(s).

Method

voidcallCleaner(ByteBuffer byteBuffer)
Perform "GC" of byte buffer
Method cleanerMethod = byteBuffer.getClass().getMethod("cleaner");
cleanerMethod.setAccessible(true);
Object cleaner = cleanerMethod.invoke(byteBuffer);
Method cleanMethod = cleaner.getClass().getMethod("clean");
cleanMethod.setAccessible(true);
cleanMethod.invoke(cleaner);
voidcleanBuffer(final ByteBuffer bb)
clean Buffer
bb.rewind();
int remain = 0;
while ((remain = bb.remaining()) > 0) {
    final int r = remain & 0x7;
    if (r == 0) {
        bb.putLong(0L);
    } else {
        if ((r & 0x4) != 0) {
...
voidcleanDirectBuffer(ByteBuffer buffer)
Force to unmap direct buffer if the buffer is no longer used.
if (buffer == null) {
    return;
if (buffer.isDirect()) {
    Cleaner cleaner = ((DirectBuffer) buffer).cleaner();
    cleaner.clean();
voidcleanMemBuff(MappedByteBuffer buffer)
clean Mem Buff
((DirectBuffer) buffer).cleaner().clean();
MethodgetCleanerMethod(final ByteBuffer buffer)
get Cleaner Method
Method result = cleanerMethodCache.get(buffer.getClass());
if (result == null) {
    result = buffer.getClass().getMethod("cleaner", (Class[]) null);
    result.setAccessible(true);
    cleanerMethodCache.put(buffer.getClass(), result);
return result;