Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 2008, 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.yaml.snakeyaml;
import org.yaml.snakeyaml.DumperOptions.FlowStyle;
import org.yaml.snakeyaml.composer.Composer;
import org.yaml.snakeyaml.constructor.BaseConstructor;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.emitter.Emitable;
import org.yaml.snakeyaml.emitter.Emitter;
import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.events.Event;
import org.yaml.snakeyaml.introspector.BeanAccess;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.parser.Parser;
import org.yaml.snakeyaml.parser.ParserImpl;
import org.yaml.snakeyaml.reader.StreamReader;
import org.yaml.snakeyaml.reader.UnicodeReader;
import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.resolver.Resolver;
import org.yaml.snakeyaml.serializer.Serializer;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.regex.Pattern;
/**
* Public YAML interface. This class is not thread-safe. Which means that all the methods of the same
* instance can be called only by one thread.
* It is better to create an instance for every YAML stream.
*/
public class Yaml {
protected final Resolver resolver;
private String name;
protected BaseConstructor constructor;
protected Representer representer;
protected DumperOptions dumperOptions;
protected LoaderOptions loadingConfig;
/**
* Create Yaml instance.
*/
public Yaml() {
this(new Constructor(), new Representer(), new DumperOptions(), new LoaderOptions(),
new Resolver());
}
/**
* Create Yaml instance.
*
* @param dumperOptions DumperOptions to configure outgoing objects
*/
public Yaml(DumperOptions dumperOptions) {
this(new Constructor(), new Representer(dumperOptions), dumperOptions);
}
/**
* Create Yaml instance.
*
* @param loadingConfig LoadingConfig to control load behavior
*/
public Yaml(LoaderOptions loadingConfig) {
this(new Constructor(loadingConfig), new Representer(), new DumperOptions(), loadingConfig);
}
/**
* Create Yaml instance.
*
* @param representer Representer to emit outgoing objects
*/
public Yaml(Representer representer) {
this(new Constructor(), representer);
}
/**
* Create Yaml instance.
*
* @param constructor BaseConstructor to construct incoming documents
*/
public Yaml(BaseConstructor constructor) {
this(constructor, new Representer());
}
/**
* Create Yaml instance.
*
* @param constructor BaseConstructor to construct incoming documents
* @param representer Representer to emit outgoing objects
*/
public Yaml(BaseConstructor constructor, Representer representer) {
this(constructor, representer, initDumperOptions(representer));
}
private static DumperOptions initDumperOptions(Representer representer) {
DumperOptions dumperOptions = new DumperOptions();
dumperOptions.setDefaultFlowStyle(representer.getDefaultFlowStyle());
dumperOptions.setDefaultScalarStyle(representer.getDefaultScalarStyle());
dumperOptions.setAllowReadOnlyProperties(representer.getPropertyUtils().isAllowReadOnlyProperties());
dumperOptions.setTimeZone(representer.getTimeZone());
return dumperOptions;
}
/**
* Create Yaml instance. It is safe to create a few instances and use them
* in different Threads.
*
* @param representer Representer to emit outgoing objects
* @param dumperOptions DumperOptions to configure outgoing objects
*/
public Yaml(Representer representer, DumperOptions dumperOptions) {
this(new Constructor(), representer, dumperOptions, new LoaderOptions(), new Resolver());
}
/**
* Create Yaml instance. It is safe to create a few instances and use them
* in different Threads.
*
* @param constructor BaseConstructor to construct incoming documents
* @param representer Representer to emit outgoing objects
* @param dumperOptions DumperOptions to configure outgoing objects
*/
public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions) {
this(constructor, representer, dumperOptions, new LoaderOptions(), new Resolver());
}
/**
* Create Yaml instance. It is safe to create a few instances and use them
* in different Threads.
*
* @param constructor BaseConstructor to construct incoming documents
* @param representer Representer to emit outgoing objects
* @param dumperOptions DumperOptions to configure outgoing objects
* @param loadingConfig LoadingConfig to control load behavior
*/
public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions,
LoaderOptions loadingConfig) {
this(constructor, representer, dumperOptions, loadingConfig, new Resolver());
}
/**
* Create Yaml instance. It is safe to create a few instances and use them
* in different Threads.
*
* @param constructor BaseConstructor to construct incoming documents
* @param representer Representer to emit outgoing objects
* @param dumperOptions DumperOptions to configure outgoing objects
* @param resolver Resolver to detect implicit type
*/
public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions,
Resolver resolver) {
this(constructor, representer, dumperOptions, new LoaderOptions(), resolver);
}
/**
* Create Yaml instance. It is safe to create a few instances and use them
* in different Threads.
*
* @param constructor BaseConstructor to construct incoming documents
* @param representer Representer to emit outgoing objects
* @param dumperOptions DumperOptions to configure outgoing objects
* @param loadingConfig LoadingConfig to control load behavior
* @param resolver Resolver to detect implicit type
*/
public Yaml(BaseConstructor constructor, Representer representer, DumperOptions dumperOptions,
LoaderOptions loadingConfig, Resolver resolver) {
if (!constructor.isExplicitPropertyUtils()) {
constructor.setPropertyUtils(representer.getPropertyUtils());
} else if (!representer.isExplicitPropertyUtils()) {
representer.setPropertyUtils(constructor.getPropertyUtils());
}
this.constructor = constructor;
this.constructor.setAllowDuplicateKeys(loadingConfig.isAllowDuplicateKeys());
this.constructor.setWrappedToRootException(loadingConfig.isWrappedToRootException());
if (dumperOptions.getIndent() <= dumperOptions.getIndicatorIndent()) {
throw new YAMLException("Indicator indent must be smaller then indent.");
}
representer.setDefaultFlowStyle(dumperOptions.getDefaultFlowStyle());
representer.setDefaultScalarStyle(dumperOptions.getDefaultScalarStyle());
representer.getPropertyUtils()
.setAllowReadOnlyProperties(dumperOptions.isAllowReadOnlyProperties());
representer.setTimeZone(dumperOptions.getTimeZone());
this.representer = representer;
this.dumperOptions = dumperOptions;
this.loadingConfig = loadingConfig;
this.resolver = resolver;
this.name = "Yaml:" + System.identityHashCode(this);
}
/**
* Serialize a Java object into a YAML String.
*
* @param data Java object to be Serialized to YAML
* @return YAML String
*/
public String dump(Object data) {
List