de.sstoehr.harreader.AbstractHarIO Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of har-reader Show documentation
Show all versions of har-reader Show documentation
A library to access HTTP archive format with Java
The newest version!
package de.sstoehr.harreader;
import java.io.IOException;
import java.util.function.Function;
import com.fasterxml.jackson.databind.ObjectMapper;
import de.sstoehr.harreader.jackson.DefaultMapperFactory;
import de.sstoehr.harreader.jackson.MapperFactory;
public abstract class AbstractHarIO {
private final MapperFactory mapperFactory;
public AbstractHarIO(MapperFactory mapperFactory) {
if (mapperFactory == null) {
throw new IllegalArgumentException("mapperFactory must not be null!");
}
this.mapperFactory = mapperFactory;
}
public AbstractHarIO() {
this(new DefaultMapperFactory());
}
protected MapperFactory getMapperFactory() {
return mapperFactory;
}
protected static T wrap(ObjectMapper mapper, IOFunction consumer,
Function exceptionFactory) throws E {
try {
return consumer.apply(mapper);
} catch(IOException thrown) {
throw exceptionFactory.apply(thrown);
}
}
@FunctionalInterface
protected interface IOFunction {
R apply(T object) throws IOException;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy