Пример #1
0
/**
 * Encodes streams in formeta format.
 *
 * @author Christoph Böhme
 */
@Description("Encodes streams in formeta format.")
@In(StreamReceiver.class)
@Out(String.class)
@FluxCommand("encode-formeta")
public final class FormetaEncoder extends DefaultStreamPipe<ObjectReceiver<String>> {

  private FormatterStyle style = FormatterStyle.CONCISE;
  private Formatter formatter = style.createFormatter();

  public FormatterStyle getStyle() {
    return style;
  }

  public void setStyle(final FormatterStyle formatterStyle) {
    this.style = formatterStyle;
    formatter = formatterStyle.createFormatter();
  }

  @Override
  public void startRecord(final String identifier) {
    formatter.reset();
    formatter.startGroup(identifier);
  }

  @Override
  public void endRecord() {
    formatter.endGroup();
    getReceiver().process(formatter.toString());
  }

  @Override
  public void startEntity(final String name) {
    formatter.startGroup(name);
  }

  @Override
  public void endEntity() {
    formatter.endGroup();
  }

  @Override
  public void literal(final String name, final String value) {
    formatter.literal(name, value);
  }
}
Пример #2
0
 public void setStyle(final FormatterStyle formatterStyle) {
   this.style = formatterStyle;
   formatter = formatterStyle.createFormatter();
 }