pl.allegro.tech.hermes.common.http.ExtraRequestHeadersCollector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-common Show documentation
Show all versions of hermes-common Show documentation
Fast and reliable message broker built on top of Kafka.
The newest version!
package pl.allegro.tech.hermes.common.http;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
public class ExtraRequestHeadersCollector implements Collector, StringBuilder, String> {
private ExtraRequestHeadersCollector() {
}
public static ExtraRequestHeadersCollector extraRequestHeadersCollector() {
return new ExtraRequestHeadersCollector();
}
@Override
public Supplier supplier() {
return StringBuilder::new;
}
@Override
public BiConsumer> accumulator() {
return (StringBuilder accumulator, Map.Entry entry) -> {
accumulator.append(entry.getKey());
accumulator.append(": ");
accumulator.append(entry.getValue());
accumulator.append('\n');
};
}
@Override
public BinaryOperator combiner() {
return StringBuilder::append;
}
@Override
public Function finisher() {
return (StringBuilder acc) -> {
if (acc.length() > 0) {
acc.setLength(acc.length() - 1);
}
return acc.toString();
};
}
@Override
public Set characteristics() {
return Collections.emptySet();
}
}