code: 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();
      }
docs: Compact the buffer
  
  @param buffer the buffer to compact
  @return true if the compact made a full buffer have space