com.frightanic.smn.core.DataLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of open-data-smn Show documentation
Show all versions of open-data-smn Show documentation
An API to serve publicly available data from the SwissMetNet.
package com.frightanic.smn.core;
import com.frightanic.smn.api.SmnData;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
public class DataLoader {
private final URL smnDataUrl;
@SneakyThrows(MalformedURLException.class)
public DataLoader(String smnDataUrl) {
this.smnDataUrl = new URL(smnDataUrl);
}
public SmnData loadSmnData() throws IOException {
try (InputStream inputStream = new BufferedInputStream(smnDataUrl.openStream(), 1024)) {
return new SmnData(IOUtils.toString(inputStream, "UTF-8"));
}
}
}