gpt4 book ai didi

java - 如何在流式传输时重命名放置在远程位置的文件

转载 作者:行者123 更新时间:2023-11-30 05:35:42 24 4
gpt4 key购买 nike

我想在从远程目录流式传输文件时向文件添加一些临时后缀。

我正在使用 Spring Integration dsl 从远程目录流式传输文件,并且我想确保一次由单个应用程序读取一个文件。所以我正在考虑在文件流式传输时向文件添加一些临时前缀。我正在使用出站网关来获取数据。

任何指示都会非常有帮助。目前我正在阅读之前和阅读之后重命名文件,我真的不想这样做。

最佳答案

考虑使用文件锁定,而不是重命名。这是13.2 读取文件 spring-integration 中的相关部分文档:

When multiple processes are reading from the same directory it can be desirable to lock files to prevent them from being picked up concurrently. To do this you can use a FileLocker. There is a java.nio based implementation available out of the box, but it is also possible to implement your own locking scheme. The nio locker can be injected as follows:

<int-file:inbound-channel-adapter id="filesIn"
directory="file:${input.directory}" prevent-duplicates="true">
<int-file:nio-locker/>
</int-file:inbound-channel-adapter>

您可以像这样配置自定义储物柜:

<int-file:inbound-channel-adapter id="filesIn"
directory="file:${input.directory}" prevent-duplicates="true">
<int-file:locker ref="customLocker"/>
</int-file:inbound-channel-adapter>

[Note] When a file inbound adapter is configured with a locker, it will take the responsibility to acquire a lock before the file is allowed to be received. It will not assume the responsibility to unlock the file. If you have processed the file and keeping the locks hanging around you have a memory leak. If this is a problem in your case you should call FileLocker.unlock(File file) yourself at the appropriate time.

请参阅 Interface FileLocker 的文档和 Class NioFileLocker了解更多信息。

关于java - 如何在流式传输时重命名放置在远程位置的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56678004/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com