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) 2018, SnakeYAML
*
* 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.representer;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import org.snakeyaml.engine.v2.api.DumpSettings;
import org.snakeyaml.engine.v2.api.RepresentToNode;
import org.snakeyaml.engine.v2.common.FlowStyle;
import org.snakeyaml.engine.v2.common.NonPrintableStyle;
import org.snakeyaml.engine.v2.common.ScalarStyle;
import org.snakeyaml.engine.v2.exceptions.YamlEngineException;
import org.snakeyaml.engine.v2.nodes.Node;
import org.snakeyaml.engine.v2.nodes.Tag;
import org.snakeyaml.engine.v2.scanner.StreamReader;
/**
* Represent standard Java classes
*/
public class StandardRepresenter extends BaseRepresenter {
/**
* all chars that represent a new line
*/
public static final Pattern MULTILINE_PATTERN = Pattern.compile("\n|\u0085");
/**
* Connect classes to their tags
*/
protected Map, Tag> classTags;
/**
* keep the options
*/
protected DumpSettings settings;
/**
* Create
*
* @param settings - configuration options
*/
public StandardRepresenter(DumpSettings settings) {
this.defaultFlowStyle = settings.getDefaultFlowStyle();
this.defaultScalarStyle = settings.getDefaultScalarStyle();
this.nullRepresenter = new RepresentNull();
this.representers.put(String.class, new RepresentString());
this.representers.put(Boolean.class, new RepresentBoolean());
this.representers.put(Character.class, new RepresentString());
this.representers.put(UUID.class, new RepresentUuid());
this.representers.put(Optional.class, new RepresentOptional());
this.representers.put(byte[].class, new RepresentByteArray());
RepresentToNode primitiveArray = new RepresentPrimitiveArray();
representers.put(short[].class, primitiveArray);
representers.put(int[].class, primitiveArray);
representers.put(long[].class, primitiveArray);
representers.put(float[].class, primitiveArray);
representers.put(double[].class, primitiveArray);
representers.put(char[].class, primitiveArray);
representers.put(boolean[].class, primitiveArray);
this.parentClassRepresenters.put(Number.class, new RepresentNumber());
this.parentClassRepresenters.put(List.class, new RepresentList());
this.parentClassRepresenters.put(Map.class, new RepresentMap());
this.parentClassRepresenters.put(Set.class, new RepresentSet());
this.parentClassRepresenters.put(Iterator.class, new RepresentIterator());
this.parentClassRepresenters.put(new Object[0].getClass(), new RepresentArray());
this.parentClassRepresenters.put(Enum.class, new RepresentEnum());
classTags = new HashMap<>();
this.settings = settings;
}
/**
* Define the way to get the Tag for any class
*
* @param clazz - the class to serialise
* @param defaultTag - the tag to use if there is no explicit configuration
* @return the Tag for output
*/
protected Tag getTag(Class> clazz, Tag defaultTag) {
return classTags.getOrDefault(clazz, defaultTag);
}
/**
* Define a tag for the Class to serialize. Should be replaced later with the beans
* project.
*
* @param clazz Class which tag is changed
* @param tag new tag to be used for every instance of the specified Class
* @return the previous tag associated with the Class
* @deprecated should be replaced with the Beans project
*/
@Deprecated
public Tag addClassTag(Class extends Object> clazz, Tag tag) {
if (tag == null) {
throw new NullPointerException("Tag must be provided.");
}
return classTags.put(clazz, tag);
}
private static class IteratorWrapper implements Iterable