All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mustachejava.util.StateAwareWriter Maven / Gradle / Ivy

There is a newer version: 0.9.14
Show newest version
package com.github.mustachejava.util;

import java.io.IOException;
import java.io.Writer;

/**
 * Manages a state machine that knows the context in an HTML document it is writing.
 */
public class StateAwareWriter extends Writer {

  // Delegate
  private Writer writer;
  private T state;

  public StateAwareWriter(Writer writer, T state) {
    this.writer = writer;
    this.state = state;
  }

  @Override
  public void write(char[] cbuf, int off, int len) throws IOException {
    state.nextState(cbuf, off, len);
    writer.write(cbuf, off, len);
  }

  @Override
  public void flush() throws IOException {
    writer.flush();
  }

  @Override
  public void close() throws IOException {
    flush();
    writer.close();
  }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy