使用 apache IOUtils.copy() 和 setContent() 复制 documentum 内容
我想将内容从一个文档库中存储的一个对象复制到另一个文档库中存储的另一个对象。我不想创建文件,因为我有超过 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 堆空间
。
如果我通过设置 Xmx max 值来调整 JVM,前面的指令是可以的,但是 targetObj.setContent(baos);
会出现 java.lang.OutOfMemoryError: Java heap space
。
只有 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) { // 成功从服务器获取数据... }
返回: 包含对象内容的 ByteArrayInputStream 对象。 投掷: DfException - 如果发生服务器错误。
和
设置内容
public boolean setContent(ByteArrayOutputStream 内容) 抛出 DfException
为对象设置新内容。当您想要设置驻留在工作内存中的数据时,请使用此方法。
以下代码示例演示了如何将驻留在内存中的内容设置到新文档:
IDfSysObject sysObj = (IDfSysObject)sess.newObject("dm_document"); sysObj.setObjectName("testDoc"); sysObj.setContentType("crtext"); 字节 b[] = {35,36,37,38,39}; ByteArrayOutputStream out = new ByteArrayOutputStream(); 输出.write(b, 0, 5); sysObj.setContent(out); sysObj.save();
参数: content - ByteArrayOutputStream 形式的内容。 投掷: DfException - 如果发生服务器错误。
I want to copy the content from one object stored in one docbase to another object stored in another docbase. I do not want to create a file because I have more than 300 k files to copy. Below is a part of my code:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copy(source.getContent(), baos);
[...]
targetObj.setContent(baos); // Documentum DFC
targetObj.save(); // Documentum DFC
If I do not tune the JVM, IOUtils.copy(source.getContent(), baos);
gives java.lang.OutOfMemoryError: Java heap space
.
If I tune the JVM by setting Xmx max value, the previous instruction is ok, but java.lang.OutOfMemoryError: Java heap space
occurs with targetObj.setContent(baos);
.
With an only 8332175 Bytes large content... (7.94 MB)
Any idea what's wrong? A better way to copy from ByteArrayInputStream to ByteArrayOutputStream? Something else?
Some Documentum API
getContent
public ByteArrayInputStream getContent()
throws DfExceptionCopies this object's content from the Documentum server into a ByteArrayInputStream >object.
The following code example demonstrates how to copy an objects content from the >Documentum server into memory:
IDfSysObject sysObj = (IDfSysObject)session.getObject(new DfId("0900d5bb8001f900")); ByteArrayInputStream bais = sysObj.getContent(); if (bais.available() > 0) { // Data successfully fetched from the server... }
Returns:
a ByteArrayInputStream object containing the objects content.
Throws:
DfException - if a server error occurs.
And
setContent
public boolean setContent(ByteArrayOutputStream content)
throws DfExceptionSets new content to an object. Use this method when you want to set data that resides >in working memory.
The following code example demonstrates how to set content residing in memory to a new document:
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();
Parameters:
content - the content as a ByteArrayOutputStream.
Throws:
DfException - if a server error occurs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只要您使用
ByteArrayOutputStream
,数据就必须适合内存。我对 Documentum 一无所知,但是是否可能存在
targetObj.setContent(File)
或setContent(InputStream)
,这样您就可以避免将整个块读入字节[]?
(8MB并不是那么大,也许你可以调整Java堆空间。它也可以帮助预先调整BAOS使用的缓冲区的大小,你可以将初始大小传递给它的构造函数)
更新:< /strong> 您确定 setContent 采用 ByteArray Output 流吗?通常,设置器将从输入流中读取。
As long as you use
ByteArrayOutputStream
, the data will have to fit in memory.I know nothing about Documentum, but is there maybe a
targetObj.setContent(File)
orsetContent(InputStream)
, so that you can avoid reading the whole chunk into abyte[]
?(8MB is not all that huge though, maybe you can just adjust the Java heap space. It could also help to pre-size the buffer used by the BAOS, you can pass the initial size to its constructor)
Update: Are you sure setContent takes a ByteArray Output Stream? Usually, a setter would read from an InputStream.
我在处理大文件时遇到过这样的问题,除了尝试增加堆大小之外,它确实没有任何魔力。我知道您说过您不想在运行代码的客户端本地创建文件,但您可能想看看通过操作来执行此操作。本质上,您只需运行导出操作以从源存储库获取文件,然后使用导入操作在目标中创建它。作为导入操作的一部分,您可以设置一个标志,以便在操作完成时删除源文件。
I've run into problems like this when dealing with large files and there really isn't any magic to it other than trying to increase your heap size. I know you said you don't want to create a file locally on the client where your code is running, but you may want to take a look at doing this with operations. Essentially you would just run an export operation to get the file from the source repository then use an import operation to create it in the target. As part of the import operation, there is a flag you can set to delete the source file when the operation completes.
如果您需要将其临时存储在内存中,请使用以下方法增加 JVM 最大内存大小:
将最大内存分配增加到 256Mb(默认为 64Mb)。请参阅此处 了解更多详情。
If you need to store this temporarily in memory, then increase your JVM max memory size using:
to increase the maximum memory allocation to 256Mb (default is 64Mb). See here for more details.