code: public void completeFrame() throws IOException {
          int frameSize = buffer.position();
          if (frameSize > 0) {
              frameSizeBuffer.rewind();
              try (ByteBufferOutputStream bos = new ByteBufferOutputStream(frameSizeBuffer);
                   BinaryWriter writer = new BigEndianBinaryWriter(bos)) {
                  writer.writeInt(frameSize);
                  bos.flush();
              }
              frameSizeBuffer.flip();
              buffer.flip();
  
              synchronized (out) {
                  out.write(frameSizeBuffer);
                  while (buffer.hasRemaining()) {
                      out.write(buffer);
                  }
              }
  
              buffer.rewind();
              buffer.limit(buffer.capacity());
          }
      }
docs: Write the frame at the current state, and reset the buffer to be able to
  generate a new frame.
  
  @throws IOException On failed write.