本文整理汇总了Java中org.yaml.snakeyaml.error.YAMLException类的典型用法代码示例。如果您正苦于以下问题:Java YAMLException类的具体用法?Java YAMLException怎么用?Java YAMLException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
YAMLException类属于org.yaml.snakeyaml.error包,在下文中一共展示了YAMLException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertStringToManifest
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
@NotNull
public static io.cdep.cdep.yml.cdepmanifest.CDepManifestYml convertStringToManifest(@NotNull String content) {
Yaml yaml = new Yaml(new Constructor(io.cdep.cdep.yml.cdepmanifest.v3.CDepManifestYml.class));
io.cdep.cdep.yml.cdepmanifest.CDepManifestYml manifest;
try {
CDepManifestYml prior = (CDepManifestYml) yaml.load(
new ByteArrayInputStream(content.getBytes(StandardCharsets
.UTF_8)));
prior.sourceVersion = CDepManifestYmlVersion.v3;
manifest = convert(prior);
require(manifest.sourceVersion == CDepManifestYmlVersion.v3);
} catch (YAMLException e) {
manifest = convert(V2Reader.convertStringToManifest(content));
}
return manifest;
}
示例2: representData
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
public Node representData(Object data) {
Tag tag = Tag.STR;
Character style = null;
String value = data.toString();
if (StreamReader.NON_PRINTABLE.matcher(value).find()) {
tag = Tag.BINARY;
char[] binary;
try {
binary = Base64Coder.encode(value.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new YAMLException(e);
}
value = String.valueOf(binary);
style = '|';
}
// if no other scalar style is explicitly set, use literal style for
// multiline scalars
if (defaultScalarStyle == null && MULTILINE_PATTERN.matcher(value).find()) {
style = '|';
}
return representScalar(tag, value, style);
}
示例3: update
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
private void update() {
if (!this.eof) {
this.buffer = buffer.substring(this.pointer);
this.pointer = 0;
try {
int converted = this.stream.read(data);
if (converted > 0) {
/*
* Let's create StringBuilder manually. Anyway str1 + str2
* generates new StringBuilder(str1).append(str2).toSting()
* Giving correct capacity to the constructor prevents
* unnecessary operations in appends.
*/
checkPrintable(data, 0, converted);
this.buffer = new StringBuilder(buffer.length() + converted).append(buffer)
.append(data, 0, converted).toString();
} else {
this.eof = true;
this.buffer += "\0";
}
} catch (IOException ioe) {
throw new YAMLException(ioe);
}
}
}
示例4: getSequencePropertyName
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
/**
* Provide the name of the property which is used when the entries form a
* sequence. The property must be a List.
*
*/
protected String getSequencePropertyName(Class<?> bean) {
Set<Property> properties = getPropertyUtils().getProperties(bean);
for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
Property property = iterator.next();
if (!List.class.isAssignableFrom(property.getType())) {
iterator.remove();
}
}
if (properties.size() == 0) {
throw new YAMLException("No list property found in " + bean);
} else if (properties.size() > 1) {
throw new YAMLException(
"Many list properties found in "
+ bean
+ "; Please override getSequencePropertyName() to specify which property to use.");
}
return properties.iterator().next().getName();
}
示例5: createEmptyJavaBean
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
protected Object createEmptyJavaBean(MappingNode node) {
try {
/**
* Using only default constructor. Everything else will be
* initialized on 2nd step. If we do here some partial
* initialization, how do we then track what need to be done on
* 2nd step? I think it is better to get only object here (to
* have it as reference for recursion) and do all other thing on
* 2nd step.
*/
java.lang.reflect.Constructor<?> c = node.getType().getDeclaredConstructor();
c.setAccessible(true);
return c.newInstance();
} catch (Exception e) {
throw new YAMLException(e);
}
}
示例6: getClassForNode
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
protected Class<?> getClassForNode(Node node) {
Class<? extends Object> classForTag = typeTags.get(node.getTag());
if (classForTag == null) {
String name = node.getTag().getClassName();
Class<?> cl;
try {
cl = getClassForName(name);
} catch (ClassNotFoundException e) {
throw new YAMLException("Class not found: " + name);
}
typeTags.put(node.getTag(), cl);
return cl;
} else {
return classForTag;
}
}
示例7: constructSequence
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected List<? extends Object> constructSequence(SequenceNode node) {
List<Object> result;
if (List.class.isAssignableFrom(node.getType()) && !node.getType().isInterface()) {
// the root class may be defined (Vector for instance)
try {
result = (List<Object>) node.getType().newInstance();
} catch (Exception e) {
throw new YAMLException(e);
}
} else {
result = createDefaultList(node.getValue().size());
}
constructSequenceStep2(node, result);
return result;
}
示例8: constructSet
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Set<? extends Object> constructSet(SequenceNode node) {
Set<Object> result;
if (!node.getType().isInterface()) {
// the root class may be defined
try {
result = (Set<Object>) node.getType().newInstance();
} catch (Exception e) {
throw new YAMLException(e);
}
} else {
result = createDefaultSet(node.getValue().size());
}
constructSequenceStep2(node, result);
return result;
}
示例9: createStyle
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
public static ScalarStyle createStyle(Character style) {
if (style == null) {
return PLAIN;
} else {
switch (style) {
case '"':
return DOUBLE_QUOTED;
case '\'':
return SINGLE_QUOTED;
case '|':
return LITERAL;
case '>':
return FOLDED;
default:
throw new YAMLException("Unknown scalar style character: " + style);
}
}
}
示例10: representData
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
public Node representData(Object data) {
Class<?> type = data.getClass().getComponentType();
if (byte.class == type) {
return representSequence(Tag.SEQ, asByteList(data), null);
} else if (short.class == type) {
return representSequence(Tag.SEQ, asShortList(data), null);
} else if (int.class == type) {
return representSequence(Tag.SEQ, asIntList(data), null);
} else if (long.class == type) {
return representSequence(Tag.SEQ, asLongList(data), null);
} else if (float.class == type) {
return representSequence(Tag.SEQ, asFloatList(data), null);
} else if (double.class == type) {
return representSequence(Tag.SEQ, asDoubleList(data), null);
} else if (char.class == type) {
return representSequence(Tag.SEQ, asCharList(data), null);
} else if (boolean.class == type) {
return representSequence(Tag.SEQ, asBooleanList(data), null);
}
throw new YAMLException("Unexpected primitive '" + type.getCanonicalName() + "'");
}
示例11: getSequencePropertyName
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
/**
* Provide the name of the property which is used when the entries form a
* sequence. The property must be a List.
* @param bean the class to provide exactly one List property
* @return name of the List property
* @throws IntrospectionException if the bean cannot be introspected
*/
protected String getSequencePropertyName(Class<?> bean) throws IntrospectionException {
Set<Property> properties = getPropertyUtils().getProperties(bean);
for (Iterator<Property> iterator = properties.iterator(); iterator.hasNext();) {
Property property = iterator.next();
if (!List.class.isAssignableFrom(property.getType())) {
iterator.remove();
}
}
if (properties.size() == 0) {
throw new YAMLException("No list property found in " + bean);
} else if (properties.size() > 1) {
throw new YAMLException(
"Many list properties found in "
+ bean
+ "; Please override getSequencePropertyName() to specify which property to use.");
}
return properties.iterator().next().getName();
}
示例12: Yaml
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
/**
* 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());
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);
}
示例13: construct
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
@Override
public Object construct(Node node) {
if (node.isTwoStepsConstruction()) {
throw new YAMLException("Unexpected referential mapping structure. Node: " + node);
}
Map<?, ?> raw = (Map<?, ?>) super.construct(node);
if (raw.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
Map<String, Object> typed = new LinkedHashMap<String, Object>(raw.size());
for (Map.Entry<?, ?> entry : raw.entrySet()) {
typed.put(entry.getKey().toString(), entry.getValue());
}
try {
return ConfigurationSerialization.deserializeObject(typed);
} catch (IllegalArgumentException ex) {
throw new YAMLException("Could not deserialize object", ex);
}
}
return raw;
}
示例14: construct
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
@Override
public Object construct( Node node )
{
if ( node.isTwoStepsConstruction() ) {
throw new YAMLException( "Unexpected referential mapping structure. Node: " + node );
}
Map<?, ?> raw = (Map<?, ?>) super.construct( node );
if ( raw.containsKey( ConfigurationSerialization.SERIALIZED_TYPE_KEY ) ) {
Map<String, Object> typed = new LinkedHashMap<String, Object>( raw.size() );
for ( Map.Entry<?, ?> entry : raw.entrySet() ) {
typed.put( entry.getKey().toString(), entry.getValue() );
}
try {
return ConfigurationSerialization.deserializeObject( typed );
} catch ( IllegalArgumentException ex ) {
throw new YAMLException( "Could not deserialize object", ex );
}
}
return raw;
}
示例15: createEmptyJavaBean
import org.yaml.snakeyaml.error.YAMLException; //导入依赖的package包/类
protected Object createEmptyJavaBean(MappingNode node)
{
try
{
/*
* Using only default constructor. Everything else will be
* initialized on 2nd step. If we do here some partial
* initialization, how do we then track what need to be done on
* 2nd step? I think it is better to get only object here (to
* have it as reference for recursion) and do all other thing on
* 2nd step.
*/
java.lang.reflect.Constructor<?> c = node.getType().getDeclaredConstructor();
c.setAccessible(true);
return c.newInstance();
}
catch (Exception e)
{
throw new YAMLException(e);
}
}