/*
 * Copyright 2015 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.template.soy.jbcsrc.api;

import java.io.IOException;

/**
 * An {@link Appendable} that can inform the writer that a buffer limit has been reached or
 * exceeded.
 *
 * <p>When {@link #softLimitReached} returns {@code true}, the writer should attempt to pause
 * writing operations and return control to the calling thread as soon as possible. This is a
 * <em>cooperative</em> rate limiting mechanism and is best effort.
 *
 * <p>Implementers should note that if {@link #softLimitReached} returns {@code true}, they should
 * continue to accept writes via the {@code .append(...)} methods. Throwing an exception when in
 * this state is a violation of the contract.
 */
public interface AdvisingAppendable extends Appendable {
  @Override
  AdvisingAppendable append(CharSequence csq) throws IOException;

  @Override
  AdvisingAppendable append(CharSequence csq, int start, int end) throws IOException;

  @Override
  AdvisingAppendable append(char c) throws IOException;

  /**
   * Indicates that an internal limit has been reached or exceeded and that write operations should
   * be suspended soon.
   */
  boolean softLimitReached();
}

@@ -856,35 +856,21 @@
 uld 
-attempt to 
 pause
-%0A *
  writing
  ope
@@ -865,16 +865,19 @@
  writing
+%0A *
  operati
@@ -914,38 +914,22 @@
 call
-ing thread as soon as possible
+er immediately
 . Th
@@ -935,19 +935,16 @@
 his is a
-%0A *
  %3Cem%3Ecoo
@@ -961,16 +961,19 @@
 em%3E rate
+%0A *
  limitin
@@ -1002,16 +1002,109 @@
 t effort
+ as renderers can provide no guarantee about how%0A * %3Cem%3Efrequently%3C/em%3E this method is called
 .%0A *%0A * 
@@ -1192,22 +1192,20 @@
 %7D, they 
-should
+must
 %0A * cont
@@ -1776,12 +1776,19 @@
 ded 
+%3Ci%3E
 soon
+%3C/i%3E
 .%0A  

Clarify documentation on AdvisingAppendable