code: private boolean parsePayload(ByteBuffer buffer) {
          if (payloadLength == 0) {
              return true;
          }
  
          if (buffer.hasRemaining()) {
              // Create a small window of the incoming buffer to work with.
              // this should only show the payload itself, and not any more
              // bytes that could belong to the start of the next frame.
              int bytesSoFar = payload == null ? 0 : payload.position();
              int bytesExpected = payloadLength - bytesSoFar;
              int bytesAvailable = buffer.remaining();
              int windowBytes = Math.min(bytesAvailable, bytesExpected);
              int limit = buffer.limit();
              buffer.limit(buffer.position() + windowBytes);
              ByteBuffer window = buffer.slice();
              buffer.limit(limit);
              buffer.position(buffer.position() + window.remaining());
  
              if (LOG.isDebugEnabled()) {
                  LOG.debug("{} Window: {}", policy.getBehavior(), BufferUtils.toDetailString(window));
              }
  
              maskProcessor.process(window);
  
              if (window.remaining() == payloadLength) {
                  // We have the whole content, no need to copy.
                  frame.setPayload(window);
                  return true;
              } else {
                  if (payload == null) {
                      payload = BufferUtils.allocate(payloadLength);
                      BufferUtils.clearToFill(payload);
                  }
                  // Copy the payload.
                  payload.put(window);
  
                  if (payload.position() == payloadLength) {
                      BufferUtils.flipToFlush(payload, 0);
                      frame.setPayload(payload);
                      return true;
                  }
              }
          }
          return false;
      }
docs: Implementation specific parsing of a payload
  
  @param buffer the payload buffer
  @return true if payload is done reading, false if incomplete