Java tutorial
/** * Copyright 2017 Open Source Osijek Community * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.blip.workflowengine.configuration; import org.blip.workflowengine.flowcomponent.Microservice; import org.blip.workflowengine.functions.FlowComponentXmlFunctions; import org.jdom2.Document; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Objects; /** * Created by root on 01.01.17.. */ public interface XmlConfigWrite extends FlowComponentXmlFunctions { default void write(final Microservice microservice, final File file) throws IOException { Objects.requireNonNull(microservice, "microservice argument is null"); Objects.requireNonNull(file, "file argument is null"); if (!file.isFile()) { throw new IllegalArgumentException("Not a file"); } else if (!file.canWrite()) { throw new IllegalArgumentException("Can't write to file"); } final XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); final Document document = new Document(microserviceToXml().apply(microservice)); out.output(document, new FileOutputStream(file)); } }