io.github.mngsk.devicedetector.operatingsystem.OperatingSystemParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of device-detector Show documentation
Show all versions of device-detector Show documentation
The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, feed readers, media players, PIMs, ...), operating systems, brands and models.
package io.github.mngsk.devicedetector.operatingsystem;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.regex.Matcher;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.github.mngsk.devicedetector.util.AbstractParser;
public class OperatingSystemParser extends AbstractParser {
private List operatingSystems;
private Map> families;
private List platforms;
public OperatingSystemParser() {
this(new ObjectMapper(new YAMLFactory()));
}
public OperatingSystemParser(ObjectMapper objectMapper) {
String fixtureFile;
InputStream inputStream;
CollectionType listType;
fixtureFile = "regexes/oss.yml";
inputStream = getClass().getClassLoader()
.getResourceAsStream(fixtureFile);
listType = objectMapper.getTypeFactory().constructCollectionType(
List.class, OperatingSystemRegex.class);
try {
this.operatingSystems = objectMapper.readValue(inputStream,
listType);
} catch (IOException e) {
throw new RuntimeException("Could not load " + fixtureFile, e);
}
fixtureFile = "regexes/ossfamilies.yml";
inputStream = getClass().getClassLoader()
.getResourceAsStream(fixtureFile);
TypeReference