Java ByteBuffer Clean cleanBuffer(final ByteBuffer bb)

Here you can find the source of cleanBuffer(final ByteBuffer bb)

Description

clean Buffer

License

Apache License

Declaration

public static void cleanBuffer(final ByteBuffer bb) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.nio.ByteBuffer;

public class Main {
    public static void cleanBuffer(final ByteBuffer bb) {
        bb.rewind();//  w w w .j  av a 2s  .  c  o  m
        int remain = 0;
        while ((remain = bb.remaining()) > 0) {
            final int r = remain & 0x7;
            if (r == 0) {
                bb.putLong(0L);
            } else {
                if ((r & 0x4) != 0) {
                    bb.putInt(0);
                }
                if ((r & 0x2) != 0) {
                    bb.putShort((short) 0);
                }
                if ((r & 0x1) != 0) {
                    bb.put((byte) 0);
                }
            }
        }
    }
}

Related

  1. callCleaner(ByteBuffer byteBuffer)
  2. cleanDirectBuffer(ByteBuffer buffer)
  3. cleanMemBuff(MappedByteBuffer buffer)
  4. getCleanerMethod(final ByteBuffer buffer)