本文整理汇总了Java中org.yaml.snakeyaml.nodes.Tag.BINARY属性的典型用法代码示例。如果您正苦于以下问题:Java Tag.BINARY属性的具体用法?Java Tag.BINARY怎么用?Java Tag.BINARY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.yaml.snakeyaml.nodes.Tag
的用法示例。
在下文中一共展示了Tag.BINARY属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: representData
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);
}
示例2: representData
public Node representData(Object data) {
Tag tag = Tag.STR;
Character style = null;
String value = data.toString();
if (!StreamReader.isPrintable(value)) {
tag = Tag.BINARY;
char[] binary;
try {
final byte[] bytes = value.getBytes("UTF-8");
// sometimes above will just silently fail - it will return incomplete data
// it happens when String has invalid code points
// (for example half surrogate character without other half)
final String checkValue = new String(bytes, "UTF-8");
if (!checkValue.equals(value)) {
throw new YAMLException("invalid string value has occurred");
}
binary = Base64Coder.encode(bytes);
} 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: representString
public final Node representString(String data)
{
Tag tag = Tag.STR;
Character style = null;
String value = data;
if (! isPrintable(value))
{
tag = Tag.BINARY;
char[] binary;
try
{
byte[] bytes = value.getBytes("UTF-8");
String checkValue = new String(bytes, "UTF-8");
if (! checkValue.equals(value))
{
throw new YAMLException("invalid string value has occurred");
}
binary = Base64Coder.encode(bytes);
}
catch (UnsupportedEncodingException var8)
{
throw new YAMLException(var8);
}
value = String.valueOf(binary);
style = '|';
}
if ((this.getDefaultScalarStyle() == null) && Representer.MULTILINE_PATTERN.matcher(value).find())
{
style = '|';
}
return this.representer.representScalar(tag, value, style);
}