本文整理汇总了Java中ca.sqlpower.util.SQLPowerUtils.copyStream方法的典型用法代码示例。如果您正苦于以下问题:Java SQLPowerUtils.copyStream方法的具体用法?Java SQLPowerUtils.copyStream怎么用?Java SQLPowerUtils.copyStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca.sqlpower.util.SQLPowerUtils
的用法示例。
在下文中一共展示了SQLPowerUtils.copyStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: persistProperty
import ca.sqlpower.util.SQLPowerUtils; //导入方法依赖的package包/类
@Override
public void persistProperty(String uuid, String propertyName,
DataType propertyType, Object newValue)
throws SPPersistenceException {
if (uuid == null) uuid = "";
if (currentObject.isEmpty()) {
throw new SPPersistenceException("Recieved property for object [" + uuid + "] which does not exist");
}
if (!uuid.equals(currentObject.peek())) {
throw new SPPersistenceException(null,
"This persister requires persists to be ordered. An property of ["
+ uuid + "] was persisted while the current object was ["
+ currentObject.peek() + "]");
}
if (propertyType != DataType.NULL && newValue != null) {
out.print(tab() + "<property name=\"" + SQLPowerUtils.escapeNewLines(SQLPowerUtils.escapeXML(propertyName)) + "\" type=\"" + propertyType.toString() + "\"");
if (propertyType == DataType.PNG_IMG) {
try {
out.print(" value=\"");
ByteArrayOutputStream data = new ByteArrayOutputStream();
SQLPowerUtils.copyStream((InputStream) newValue, data);
byte[] bytes = data.toByteArray();
byte[] base64Bytes = Base64.encodeBase64(bytes);
out.print(new String(base64Bytes));
out.println("\"/>");
} catch (IOException e) {
throw new SPPersistenceException(uuid, e);
}
} else {
out.println(" value=\"" + SQLPowerUtils.escapeXML(newValue.toString()) + "\"/>");
}
}
}
示例2: setValueInJSONObject
import ca.sqlpower.util.SQLPowerUtils; //导入方法依赖的package包/类
/**
* Sets the named property of the given JSON object to the given value. This
* is a nontrivial operation because JSON nulls are special, and so are
* values of type PNG_IMAGE.
*
* @param jsonObject
* The object whose property to set.
* @param jsonPropName
* The property name to set on jsonObject.
* @param type
* the SPPersister framework datatype for value.
* @param value
* The actual value to set. Values for all possible DataTypes are
* properly converted to a JavaScript data type before being set.
*/
private void setValueInJSONObject(JSONObject jsonObject, String jsonPropName, DataType type, Object value)
throws IOException, JSONException, UnsupportedEncodingException {
if (type == DataType.PNG_IMG && value != null) {
InputStream in = (InputStream) value;
ByteArrayOutputStream out = new ByteArrayOutputStream();
SQLPowerUtils.copyStream(in, out);
byte[] bytes = out.toByteArray();
byte[] base64Bytes = Base64.encodeBase64(bytes);
jsonObject.put(jsonPropName, new String(base64Bytes, "ascii"));
} else {
jsonObject.put(jsonPropName, value == null ? JSONObject.NULL : value);
}
}