Search in sources :

Example 1 with UgsDesign

use of com.willwinder.ugs.nbp.designer.io.ugsd.common.UgsDesign in project Universal-G-Code-Sender by winder.

the class UgsDesignReader method read.

@Override
public Optional<Design> read(InputStream resourceAsStream) {
    try {
        String designFileContent = IOUtils.toString(resourceAsStream, StandardCharsets.UTF_8);
        if (StringUtils.isEmpty(designFileContent)) {
            return Optional.empty();
        }
        Gson gson = new GsonBuilder().create();
        UgsDesign design = gson.fromJson(designFileContent, UgsDesign.class);
        if (DesignV1.VERSION.equals(design.getVersion())) {
            return parseV1(designFileContent);
        }
        throw new RuntimeException("Unknown version " + design.getVersion());
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Couldn't load stream", e);
        throw new RuntimeException("Couldn't read from stream", e);
    }
}
Also used : UgsDesign(com.willwinder.ugs.nbp.designer.io.ugsd.common.UgsDesign) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 UgsDesign (com.willwinder.ugs.nbp.designer.io.ugsd.common.UgsDesign)1