public void readBlocking(StreamSourceFrameChannel channel) throws IOException {
   if (current == null) {
     current = channel.getWebSocketChannel().getBufferPool().allocate();
   }
   for (; ; ) {
     int res = channel.read(current.getResource());
     if (res == -1) {
       complete = true;
       return;
     } else if (res == 0) {
       channel.awaitReadable();
     }
     checkMaxSize(channel, res);
     if (bufferFullMessage) {
       dealWithFullBuffer(channel);
     } else if (!current.getResource().hasRemaining()) {
       return;
     }
   }
 }
  public void read(
      final StreamSourceFrameChannel channel,
      final WebSocketCallback<BufferedBinaryMessage> callback) {
    try {
      for (; ; ) {
        if (current == null) {
          current = channel.getWebSocketChannel().getBufferPool().allocate();
        }
        int res = channel.read(current.getResource());
        if (res == -1) {
          this.complete = true;
          callback.complete(channel.getWebSocketChannel(), this);
          return;
        } else if (res == 0) {
          channel
              .getReadSetter()
              .set(
                  new ChannelListener<StreamSourceFrameChannel>() {
                    @Override
                    public void handleEvent(StreamSourceFrameChannel channel) {
                      try {
                        for (; ; ) {
                          if (current == null) {
                            current = channel.getWebSocketChannel().getBufferPool().allocate();
                          }
                          int res = channel.read(current.getResource());
                          if (res == -1) {
                            complete = true;
                            channel.suspendReads();
                            callback.complete(
                                channel.getWebSocketChannel(), BufferedBinaryMessage.this);
                            return;
                          } else if (res == 0) {
                            return;
                          }

                          checkMaxSize(channel, res);
                          if (bufferFullMessage) {
                            dealWithFullBuffer(channel);
                          } else if (!current.getResource().hasRemaining()) {
                            callback.complete(
                                channel.getWebSocketChannel(), BufferedBinaryMessage.this);
                          } else {
                            handleNewFrame(channel, callback);
                          }
                        }
                      } catch (IOException e) {
                        channel.suspendReads();
                        callback.onError(
                            channel.getWebSocketChannel(), BufferedBinaryMessage.this, e);
                      }
                    }
                  });
          channel.resumeReads();
          return;
        }

        checkMaxSize(channel, res);
        if (bufferFullMessage) {
          dealWithFullBuffer(channel);
        } else if (!current.getResource().hasRemaining()) {
          callback.complete(channel.getWebSocketChannel(), BufferedBinaryMessage.this);
        } else {
          handleNewFrame(channel, callback);
        }
      }
    } catch (IOException e) {
      callback.onError(channel.getWebSocketChannel(), this, e);
    }
  }