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

org.snakeyaml.engine.v2.api.lowlevel.Serialize Maven / Gradle / Ivy

/**
 * Copyright (c) 2018, http://www.snakeyaml.org
 * 

* 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.snakeyaml.engine.v2.api.lowlevel; import org.snakeyaml.engine.v2.api.DumpSettings; import org.snakeyaml.engine.v2.emitter.Emitable; import org.snakeyaml.engine.v2.events.Event; import org.snakeyaml.engine.v2.nodes.Node; import org.snakeyaml.engine.v2.serializer.Serializer; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; public class Serialize { private final DumpSettings settings; /** * Create instance with provided {@link DumpSettings} * * @param settings - configuration */ public Serialize(DumpSettings settings) { Objects.requireNonNull(settings, "DumpSettings cannot be null"); this.settings = settings; } /** * Serialize a {@link Node} and produce events. * * @param node - {@link Node} to serialize * @return serialized events * @see Processing Overview */ public List serializeOne(Node node) { Objects.requireNonNull(node, "Node cannot be null"); return serializeAll(Collections.singletonList(node)); } /** * Serialize {@link Node}s and produce events. * * @param nodes - {@link Node}s to serialize * @return serialized events * @see Processing Overview */ public List serializeAll(List nodes) { Objects.requireNonNull(nodes, "Nodes cannot be null"); EmitableEvents emitableEvents = new EmitableEvents(); Serializer serializer = new Serializer(settings, emitableEvents); serializer.open(); for (Node node : nodes) { serializer.serialize(node); } serializer.close(); return emitableEvents.getEvents(); } } class EmitableEvents implements Emitable { private final List events = new ArrayList<>(); @Override public void emit(Event event) { events.add(event); } public List getEvents() { return events; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy