本文整理汇总了Java中lotus.domino.Document.getMIMEEntity方法的典型用法代码示例。如果您正苦于以下问题:Java Document.getMIMEEntity方法的具体用法?Java Document.getMIMEEntity怎么用?Java Document.getMIMEEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lotus.domino.Document
的用法示例。
在下文中一共展示了Document.getMIMEEntity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveState
import lotus.domino.Document; //导入方法依赖的package包/类
/**
* Save state. Imported from org.openntf.domino
*
* @param object
* the object
* @param doc
* the doc
* @param itemName
* the item name
* @param compress
* the compress
* @throws Throwable
* the throwable
*/
public static void saveState(Serializable object, Document doc, String itemName, boolean compress, Map<String, String> headers) throws Throwable {
Session session=doc.getParentDatabase().getParent();
boolean convertMime = session.isConvertMime();
session.setConvertMime(false);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream objectStream = compress ? new ObjectOutputStream(new GZIPOutputStream(byteStream)) : new ObjectOutputStream(
byteStream);
String contentType = null;
// Prefer externalization if available
if(object instanceof Externalizable) {
((Externalizable)object).writeExternal(objectStream);
contentType = "application/x-java-externalized-object";
} else {
objectStream.writeObject(object);
contentType = "application/x-java-serialized-object";
}
objectStream.flush();
objectStream.close();
Stream mimeStream = session.createStream();
MIMEEntity previousState = doc.getMIMEEntity(itemName);
MIMEEntity entity = previousState == null ? doc.createMIMEEntity(itemName) : previousState;
ByteArrayInputStream byteIn = new ByteArrayInputStream(byteStream.toByteArray());
mimeStream.setContents(byteIn);
entity.setContentFromBytes(mimeStream, contentType, MIMEEntity.ENC_NONE);
MIMEHeader contentEncoding = entity.getNthHeader("Content-Encoding");
if (compress) {
if (contentEncoding == null) {
contentEncoding = entity.createHeader("Content-Encoding");
}
contentEncoding.setHeaderVal("gzip");
contentEncoding.recycle();
} else {
if (contentEncoding != null) {
contentEncoding.remove();
contentEncoding.recycle();
}
}
MIMEHeader javaClass = entity.getNthHeader("X-Java-Class");
if (javaClass == null) {
javaClass = entity.createHeader("X-Java-Class");
}
javaClass.setHeaderVal(object.getClass().getName());
javaClass.recycle();
if(headers != null) {
for(Map.Entry<String, String> entry : headers.entrySet()) {
MIMEHeader paramHeader = entity.getNthHeader(entry.getKey());
if(paramHeader == null) {
paramHeader = entity.createHeader(entry.getKey());
}
paramHeader.setHeaderVal(entry.getValue());
paramHeader.recycle();
}
}
entity.recycle();
mimeStream.recycle();
session.setConvertMime(convertMime);
}