Here you can find the source of compact(ByteBuffer buffer)
Parameter | Description |
---|---|
buffer | the buffer to compact |
public static boolean compact(ByteBuffer buffer)
//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(); } }