本文整理汇总了Java中lotus.domino.Document.createMIMEEntity方法的典型用法代码示例。如果您正苦于以下问题:Java Document.createMIMEEntity方法的具体用法?Java Document.createMIMEEntity怎么用?Java Document.createMIMEEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lotus.domino.Document
的用法示例。
在下文中一共展示了Document.createMIMEEntity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: writeMimeOutput
import lotus.domino.Document; //导入方法依赖的package包/类
private void writeMimeOutput(Document document, String itemName, Writer writer)
throws NotesException, IOException {
MIMEEntity mimeEntity = null;
MIMEEntity mChild = null;
String contenttype = null;
String headers = null;
MimeEntityHelper helper = null;
if (!document.hasItem(itemName)) {
// SPR# WJBJ9PE86G: The body item doesn't exist, so create one now
mimeEntity = document.createMIMEEntity(itemName);
}
else {
helper = new MimeEntityHelper(document, itemName);
mimeEntity = helper.getFirstMimeEntity();
if (mimeEntity == null) {
throw new NullPointerException("Invalid item."); // $NLX-MimeMessageGenerator_InvalidItem-1$
}
}
try {
contenttype = mimeEntity.getContentType();
headers = mimeEntity.getHeaders();
// TODO: Is there a better way to output the headers?
if (!headers.startsWith("MIME-Version:")) { //$NON-NLS-1$
writer.write("MIME-Version: 1.0"); //$NON-NLS-1$
}
// Write MIMEEntity.
writeMimeEntity(writer, mimeEntity);
if (contenttype.startsWith(MULTIPART)) {
mChild = mimeEntity.getFirstChildEntity();
while (mChild != null) {
// Write MIMEEntity.
writeMimeEntity(writer, mChild);
MIMEEntity mChild2 = mChild.getFirstChildEntity();
if (mChild2 == null) {
mChild2 = mChild.getNextSibling();
if (mChild2 == null) {
mChild2 = mChild.getParentEntity();
if (mChild2 != null)
mChild2 = mChild2.getNextSibling();
}
}
mChild.recycle();
mChild = mChild2;
}
}
writer.write(mimeEntity.getBoundaryEnd());
} finally {
if (helper != null) {
helper.recycle();
}
}
}