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

de.sstoehr.harreader.AbstractHarIO Maven / Gradle / Ivy

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