Code example for CharSource

Methods: read

0
      } 
      append(out, Mode.ESCAPED, contents);
      appendSourceUrl(out, Mode.ESCAPED);
      out.append("\"));");
    } else { 
      out.append(contents.read());
      appendSourceUrl(out, Mode.NORMAL);
    } 
  } 
 
  private void appendGoogModule(Appendable out, CharSource contents)
      throws IOException {
    if (useEval) {
      out.append("goog.loadModule(\"");
      append(out, Mode.ESCAPED, contents);
      appendSourceUrl(out, Mode.ESCAPED);
      out.append("\");");
    } else { 
      // add the prefix on the first line so the line numbers aren't affected. 
      out.append(
          "goog.loadModule(function(exports) {" 
          + "'use strict';"); 
      append(out, Mode.NORMAL, contents);
      out.append(
          "\n" // terminate any trailing single line comment. 
          + ";" // terminate any trailing expression. 
          + "return exports;});\n"); 
      appendSourceUrl(out, Mode.NORMAL);
    } 
  } 
 
  private enum Mode { 
    ESCAPED,
    NORMAL,
  } 
 
  private void appendEscaped(Appendable out, String s) throws IOException {
    out.append(SourceCodeEscapers.javascriptEscaper().escape(s));
  } 
 
  private void append(Appendable out, Mode mode, String s) throws IOException {
    if (mode == Mode.ESCAPED) {
      appendEscaped(out, s);
    } else { 
      out.append(s);
    } 
  } 
 
  private void append(Appendable out, Mode mode, CharSource cs)
      throws IOException {
    append(out, mode, cs.read());
  } 
 
  private void appendSourceUrl(Appendable out, Mode mode)
      throws IOException {
    if (sourceUrl != null) {
Contextual code suggestions in your IDE  Get Codota for Java