package com.cloudera.flume.core;
import java.io.IOException;
import java.util.Map.Entry;
import com.cloudera.flume.conf.Context;
import com.cloudera.flume.conf.SinkFactory.SinkDecoBuilder;
import com.google.common.base.Preconditions;
EventSinkDecorator<S> {
final String formatString;
super(s);
Preconditions.checkNotNull(formatString);
this.formatString = formatString;
}
public void append(Event e)
throws IOException {
Preconditions.checkNotNull(e);
String body = e.escapeString(formatString);
Event e2 = new EventImpl(body.getBytes(), e.getTimestamp(),
e.getPriority(), e.getNanos(), e.getHost());
for (Entry<String, byte[]> entry : e.getAttrs().entrySet()) {
e2.set(entry.getKey(), entry.getValue());
}
super.append(e2);
}
public static SinkDecoBuilder
builder() {
return new SinkDecoBuilder() {
@Override
public EventSinkDecorator<EventSink>
build(Context context,
String... argv) {
Preconditions.checkArgument(argv.length == 1, "usage: format(pattern)");
return new FormatterDecorator<EventSink>(null, argv[0]);
}
};
}
}