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

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

There is a newer version: 2.3.0
Show newest version
package de.sstoehr.harreader;

import com.fasterxml.jackson.databind.ObjectMapper;
import de.sstoehr.harreader.jackson.DefaultMapperFactory;
import de.sstoehr.harreader.jackson.MapperFactory;
import de.sstoehr.harreader.model.Har;

import java.io.File;
import java.io.IOException;

public class HarReader {

    private final MapperFactory mapperFactory;

    public HarReader(MapperFactory mapperFactory) {
        if (mapperFactory == null) {
            throw new IllegalArgumentException("mapperFactory must not be null!");
        }
        this.mapperFactory = mapperFactory;
    }

    public HarReader() {
        this(new DefaultMapperFactory());
    }

    public Har readFromFile(File har) throws HarReaderException {
        return this.readFromFile(har, HarReaderMode.STRICT);
    }

    public Har readFromFile(File har, HarReaderMode mode) throws HarReaderException {
        ObjectMapper mapper = mapperFactory.instance(mode);
        try {
            return mapper.readValue(har, Har.class);
        } catch (IOException e) {
            throw new HarReaderException(e);
        }
    }

    public Har readFromString(String har) throws HarReaderException {
        return this.readFromString(har, HarReaderMode.STRICT);
    }

    public Har readFromString(String har, HarReaderMode mode) throws HarReaderException {
        ObjectMapper mapper = mapperFactory.instance(mode);
        try {
            return mapper.readValue(har, Har.class);
        } catch (IOException e) {
            throw new HarReaderException(e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy