de.sstoehr.harreader.HarReader 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
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);
}
}
}