Java Utililty Methods ByteBuffer Clear

List of utility methods to do ByteBuffer Clear

Description

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

Method

voidclear(ByteBuffer b)
clear
b.reset(); 
b.limit(b.capacity());
voidclear(ByteBuffer buffer)
Clear the buffer to be empty in flush mode.
if (buffer != null) {
    buffer.position(0);
    buffer.limit(0);
voidclear(ByteBuffer buffer, int position, int length, byte filler)
clear
assert buffer != null;
prepare(buffer, position, length);
fill(buffer, position, buffer.limit(), filler);
voidclear(ByteBuffer[] buffers)
clear
if (buffers == null) {
    return;
for (ByteBuffer buffer : buffers) {
    if (buffer != null) {
        buffer.clear();
voidclearAll(ByteBuffer[] buffers)
Convenience method to clear array of buffers.
for (int i = buffers.length; i-- > 0;)
    buffers[i].clear();
ByteBufferclearAndEnsureCapacity(ByteBuffer buffer, int elements)
Ensure the buffer's capacity is large enough to hold a given number of elements.
if (buffer == null || buffer.capacity() < elements) {
    buffer = ByteBuffer.allocate(elements);
} else {
    buffer.clear();
return buffer;
voidclearRemaining(ByteBuffer buffer)
Sets all bits in the given remaining byte range to 0.
if (!buffer.hasRemaining()) {
    return;
int pos = buffer.position();
clearRange(buffer, pos, pos + buffer.remaining());
voidclearRemainingFrame(ByteBuffer buffer, int position)
clear Remaining Frame
buffer.array()[position] = 0;
voidclearString(ByteBuffer buffer)
clear String
byte[] data = new byte[buffer.capacity()];
for (int i = 0; i < data.length; i++) {
    data[i] = '0';
buffer.clear();
buffer.put(data);
buffer.clear();
booleanfillBuffer(ReadableByteChannel channel, ByteBuffer buf, boolean clear)
fill Buffer
if (clear) {
    buf.clear();
while (true) {
    int cnt = channel.read(buf);
    if (cnt < 0) {
        return false;
    if (buf.position() == buf.capacity()) {
        break;
return true;