本文整理匯總了Java中org.yaml.snakeyaml.nodes.Tag.STR屬性的典型用法代碼示例。如果您正苦於以下問題:Java Tag.STR屬性的具體用法?Java Tag.STR怎麽用?Java Tag.STR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.yaml.snakeyaml.nodes.Tag
的用法示例。
在下文中一共展示了Tag.STR屬性的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);
}