本文整理汇总了Java中org.febit.util.StringUtil.escapeUTF8方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtil.escapeUTF8方法的具体用法?Java StringUtil.escapeUTF8怎么用?Java StringUtil.escapeUTF8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.febit.util.StringUtil
的用法示例。
在下文中一共展示了StringUtil.escapeUTF8方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderJson
import org.febit.util.StringUtil; //导入方法依赖的package包/类
public static Object renderJson(ActionRequest actionRequest, Object value, String boxName, String[] profiles) throws IOException {
final HttpServletResponse response = actionRequest.response;
final String encoding = response.getCharacterEncoding();
response.setContentType(MimeTypes.MIME_APPLICATION_JSON);
response.setCharacterEncoding(encoding);
final OutputStream out = response.getOutputStream();
try {
if (value == null) {
out.write("{}".getBytes(encoding));
return null;
}
final boolean hasBox = (boxName != null && !boxName.isEmpty());
final StringBuilder buffer = new StringBuilder(255);
if (hasBox) {
buffer.append("{\"").append(boxName).append("\":");
}
if (value instanceof Integer) {
buffer.append((Integer) value);
} else if (value instanceof String) {
StringUtil.escapeUTF8((String) value, buffer, true);
} else {
Json.writeTo(buffer, value, profiles);
}
if (hasBox) {
buffer.append('}');
}
out.write(buffer.toString().getBytes(encoding));
} finally {
//Notice: no close
out.flush();
}
return null;
}
示例2: resolveValidationMessage
import org.febit.util.StringUtil; //导入方法依赖的package包/类
protected static String resolveValidationMessage(Vtor vtor, String bundleName, Locale locale) {
final String msg = I18nUtil.findMessage(bundleName, locale, vtor.message);
if (msg != null) {
return StringUtil.escapeUTF8(BEAN_TEMPLATE_PARSER.parse(msg, vtor));
}
return StringPool.EMPTY;
}
示例3: renderErrorJson
import org.febit.util.StringUtil; //导入方法依赖的package包/类
public static Object renderErrorJson(final ActionRequest actionRequest, int code, String msg, Object[] args) throws IOException {
msg = resolveMessage(actionRequest, msg);
final StringBuilder buffer = new StringBuilder((msg != null ? (msg.length() << 1) : 0) + 20);
buffer.append("{\"code\":").append(code);
if (msg != null) {
buffer.append(",\"msg\":");
StringUtil.escapeUTF8(args == null || args.length == 0 ? msg : StringUtil.format(msg, args), buffer, true);
}
ServletUtil.setContentAndContentType(
actionRequest.response,
RenderUtil.MIME_TEXT_JSON,
buffer.append('}').toString());
return null;
}