Java ByteBuffer Compact compact(ByteBuffer buffer)

Here you can find the source of compact(ByteBuffer buffer)

Description

Compact the buffer

License

Open Source License

Parameter

Parameter Description
buffer the buffer to compact

Return

true if the compact made a full buffer have space

Declaration

public static boolean compact(ByteBuffer buffer) 

Method Source Code

//package com.java2s;
//  are made available under the terms of the Eclipse Public License v1.0

import java.nio.ByteBuffer;

public class Main {
    /** Compact the buffer
     * @param buffer the buffer to compact
     * @return true if the compact made a full buffer have space
     *//*from  w ww  .  j ava  2 s.  com*/
    public static boolean compact(ByteBuffer buffer) {
        if (buffer.position() == 0)
            return false;
        boolean full = buffer.limit() == buffer.capacity();
        buffer.compact().flip();
        return full && buffer.limit() < buffer.capacity();
    }
}

Related

  1. compact(ByteBuffer buffer)
  2. compact(ByteBuffer buffer)
  3. compact(ByteBuffer[] buffers)
  4. toCompactArray(ByteBuffer src)