code: protected int grabFlowControlBytes(int toSend) {
          synchronized (flowControlLock) {
              if (toSend == 0) {
                  return 0;
              }
              int newWindowSize = this.getChannel().getInitialSendWindowSize();
              int settingsDelta = newWindowSize - this.initialWindowSize;
              //first adjust for any settings frame updates
              this.initialWindowSize = newWindowSize;
              this.flowControlWindow += settingsDelta;
  
              int min = Math.min(toSend, this.flowControlWindow);
              int actualBytes = this.getChannel().grabFlowControlBytes(min);
              this.flowControlWindow -= actualBytes;
              return actualBytes;
          }
      }
docs: This method should be called before sending. It will return the amount of
  data that can be sent, taking into account the stream and connection flow
  control windows, and the toSend parameter.
  <p>
  It will decrement the flow control windows by the amount that can be sent,
  so this method should only be called as a frame is being queued.
  
  @return The number of bytes that can be sent