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

com.farao_community.farao.data.flowbased_domain.json.JsonFlowbasedDomain Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2018, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.farao_community.farao.data.flowbased_domain.json;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.powsybl.commons.json.JsonUtil;
import com.farao_community.farao.data.flowbased_domain.DataDomain;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;

/**
 * Utility class for flowbased domain JSON IO
 *
 * @author Sebastien Murgey {@literal }
 */
public final class JsonFlowbasedDomain {

    private JsonFlowbasedDomain() {
    }

    public static void write(DataDomain result, OutputStream os) {
        try {
            ObjectMapper objectMapper = createObjectMapper();
            ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter();
            writer.writeValue(os, result);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    public static DataDomain read(InputStream is) {
        try {
            ObjectMapper objectMapper = createObjectMapper();
            return objectMapper.readValue(is, DataDomain.class);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    private static ObjectMapper createObjectMapper() {
        return JsonUtil.createObjectMapper();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy