001package io.avaje.http.generator.core;
002
003import java.io.IOException;
004import java.io.Writer;
005
006/**
007 * Helper that wraps a writer with some useful methods to append content.
008 */
009public class Append {
010
011  private final Writer writer;
012
013  public Append(Writer writer) {
014    this.writer = writer;
015  }
016
017  public Append append(String content) {
018    try {
019      writer.append(content);
020      return this;
021    } catch (IOException e) {
022      throw new RuntimeException(e);
023    }
024  }
025
026  public void close() {
027    try {
028      writer.flush();
029      writer.close();
030    } catch (IOException e) {
031      throw new RuntimeException(e);
032    }
033  }
034
035  public Append eol() {
036    try {
037      writer.append("\n");
038      return this;
039    } catch (IOException e) {
040      throw new RuntimeException(e);
041    }
042  }
043
044  /**
045   * Append content with formatted arguments.
046   */
047  public Append append(String format, Object... args) {
048    return append(String.format(format, args));
049  }
050
051}