使用 apache IOUtils.copy() 和 setContent() 复制 documentum 内容

发布于 2024-08-10 21:06:47 字数 2045 浏览 4 评论 0原文

我想将内容从一个文档库中存储的一个对象复制到另一个文档库中存储的另一个对象。我不想创建文件,因为我有超过 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 DfException

Copies 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 DfException

Sets 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

德意的啸 2024-08-17 21:06:47

只要您使用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) or setContent(InputStream), so that you can avoid reading the whole chunk into a byte[]?

(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.

帝王念 2024-08-17 21:06:47

我在处理大文件时遇到过这样的问题,除了尝试增加堆大小之外,它确实没有任何魔力。我知道您说过您不想在运行代码的客户端本地创建文件,但您可能想看看通过操作来执行此操作。本质上,您只需运行导出操作以从源存储库获取文件,然后使用导入操作在目标中创建它。作为导入操作的一部分,您可以设置一个标志,以便在操作完成时删除源文件。

   IDfClientEx clientx = new DfClientEx();
   IDfExportOperation exOp = clientx.getExportOperation();
   IDfSysObject exportObj = getObjectToExport();
   IDfExportNode = (IDfExportNode) exOp.add(exportObj);
   exOp.execute();
   String path = exOp.getFilePath();

   IDfImportOperation impOper = clientx.getImportOperation();
   IDfFile dfFile = new DfFile(path);
   IDfImportNode impNode = (IDfImportNode) impOper.add(dfFile);
   impNode.setDocbaseObjectType("dm_document");
   impNode.setDestinationFolderId(importFolderId);
   impNode.setNewObjectName("testDoc");
   impNode.setFormat("crtext");
   impOper.setKeepLocalFile(false);
   impOper.execute();

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.

   IDfClientEx clientx = new DfClientEx();
   IDfExportOperation exOp = clientx.getExportOperation();
   IDfSysObject exportObj = getObjectToExport();
   IDfExportNode = (IDfExportNode) exOp.add(exportObj);
   exOp.execute();
   String path = exOp.getFilePath();

   IDfImportOperation impOper = clientx.getImportOperation();
   IDfFile dfFile = new DfFile(path);
   IDfImportNode impNode = (IDfImportNode) impOper.add(dfFile);
   impNode.setDocbaseObjectType("dm_document");
   impNode.setDestinationFolderId(importFolderId);
   impNode.setNewObjectName("testDoc");
   impNode.setFormat("crtext");
   impOper.setKeepLocalFile(false);
   impOper.execute();
古镇旧梦 2024-08-17 21:06:47

如果您需要将其临时存储在内存中,请使用以下方法增加 JVM 最大内存大小:

java -Xmx256m

将最大内存分配增加到 256Mb(默认为 64Mb)。请参阅此处 了解更多详情。

If you need to store this temporarily in memory, then increase your JVM max memory size using:

java -Xmx256m

to increase the maximum memory allocation to 256Mb (default is 64Mb). See here for more details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文