class CharStream {
  String remaining;
  int toConsume;

  CharStream(String input) {
    this.remaining = checkNotNull(input);
  }

  boolean tryConsume(String expected) {
    if (!remaining.startsWith(expected)) {
      return false;
    }
    toConsume = expected.length();
    return true;
  }

  /*
   * @param pattern the pattern to search for, which must be anchored to match only at position 0
   */
  boolean tryConsumeRegex(Pattern pattern) {
    Matcher matcher = pattern.matcher(remaining);
    if (!matcher.find()) {
      return false;
    }
    checkArgument(matcher.start() == 0);
    toConsume = matcher.end();
    return true;
  }

  String readAndResetRecorded() {<FILL_FUNCTION_BODY>}

  boolean isExhausted() {
    return remaining.isEmpty();
  }
}

    String result = remaining.substring(0, toConsume);
    remaining = remaining.substring(toConsume);
    toConsume = 0; // TODO(cpovirk): Set this to a bogus value here and in the constructor.
    return result;
  
<no_super_class>