code: public final void flush() {
          int totalBytes = 0;
          int amountToPoll = outgoingPackets.size();
          
          Packet packet;
  
          boolean shouldEncrypt = encryption != null;
          
          var queue = new ArrayDeque<byte[]>();
  
          while (amountToPoll-- > 0 && (packet = outgoingPackets.poll()) != null) {
              int currentBytes = totalBytes;
  
              boolean tooBig = (totalBytes += packet.getSize(this)) >= bufferSize;
              boolean empty = outgoingPackets.isEmpty();
  
              if (!tooBig || empty) {
                  queue.addAll(packet.getQueue());
              }
  
              // If we've buffered all of the packets that we can, send them off.
              if (tooBig || empty) {
                  var raw = DIRECT_BUFFER_POOL.take(empty ? totalBytes : currentBytes);
                  
                  byte[] input;
                  
                  try {
                      while ((input = queue.pollFirst()) != null) {
                          raw.put(shouldEncrypt ? encryption.doFinal(input) : input);
                      }
                  } catch (Exception e) {
                      throw new IllegalStateException("An exception occurred whilst encrypting data:", e);
                  }
                  
                  raw.flip();
                  
                  queue.addAll(packet.getQueue());
                  
                  // It is important to synchronize on the packetsToFlush here, as we don't want the callback to
                  // complete before the packet is queued.
                  synchronized (packetsToFlush) {
                      if (!writing.getAndSet(true)) {
                          channel.write(raw, new Tuple<>(this, raw), PACKET_HANDLER);
                      } else {
                          packetsToFlush.offerFirst(raw);
                      }
                  }
  
                  totalBytes = packet.getSize(this);
              }
          }
      }
docs: Flushes any queued {@link Packet}s held within the internal {@link Queue}.
  <br><br>
  Any {@link Packet}s queued after the call to this method will not be flushed until this method is called again.