我想将内容从存储在一个文档库中的一个对象复制到存储在另一个文档库中的另一个对象。我不想创建文件,因为我有超过 300 k 的文件要复制。以下是我的代码的一部分:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(source.getContent(), baos);
[...]
targetObj.setContent(baos); // Documentum DFC
targetObj.save(); // Documentum DFC
如果我不调整JVM,IOUtils.copy(source.getContent(), baos);
则给出java.lang.OutOfMemoryError: Java heap space
.
如果我通过设置 Xmx 最大值来调整 JVM,那么前面的指令是可以的,但是java.lang.OutOfMemoryError: Java heap space
会出现targetObj.setContent(baos);
.
只有 8332175 字节的大内容... (7.94 MB)
知道有什么问题吗?从 ByteArrayInputStream 复制到 ByteArrayOutputStream 的更好方法?还有什么?
一些 Documentum API
获取内容
公共 ByteArrayInputStream getContent() 抛出 DfException
将此对象的内容从 Documentum 服务器复制到 ByteArrayInputStream > 对象中。
以下代码示例演示如何将对象内容从 >Documentum 服务器复制到内存中:
IDfSysObject sysObj = (IDfSysObject)session.getObject(new DfId("0900d5bb8001f900")); ByteArrayInputStream bais = sysObj.getContent(); if (bais.available() > 0) { // Data successfully fetched from the server... }
返回: 包含对象内容的 ByteArrayInputStream 对象。抛出: DfException - 如果发生服务器错误。
和
设置内容
公共布尔 setContent(ByteArrayOutputStream 内容)抛出 DfException
为对象设置新内容。当您想要设置驻留在工作内存中的数据时,请使用此方法。
以下代码示例演示了如何将驻留在内存中的内容设置为新文档:
IDfSysObject sysObj = (IDfSysObject)sess.newObject("dm_document"); sysObj.setObjectName("testDoc"); sysObj.setContentType("crtext"); byte b[] = {35,36,37,38,39}; ByteArrayOutputStream out = new ByteArrayOutputStream(); out.write(b, 0, 5); sysObj.setContent(out); sysObj.save();
参数: content - 作为 ByteArrayOutputStream 的内容。抛出: DfException - 如果发生服务器错误。