VFS 方法无法处理由 JBoss解析的此 URI${jboss.server.temp.dir}/local/outgoing配置。当我尝试解析 URI 并获取文件时,它会引发异常。任何想法可能是什么问题?jboss-beans.xml"C:\\Download\\jboss-eap-5.1.1\\server\\default\\tmp/local/outgoing"
Exception
17:35:25,024 ERROR [VfsSynchronizerConfImpl] File FromOutgoing cannot be resolved, FileSystemException:
org.apache.commons.vfs2.FileSystemException: Could not find file with URI "C:\Download\jboss-eap-5.1.1\server\default\tmp/local/outgoing" because it is a relative path, and no base URI was provided.
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:719)
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:649)
at org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:605)
Run Code Online (Sandbox Code Playgroud)
DefaultFileSystemManager.class methods
public FileObject resolveFile(final String uri) throws FileSystemException
-- this method calls the method below
public FileObject resolveFile(final FileObject baseFile, final String uri,
final FileSystemOptions fileSystemOptions)
throws FileSystemException
-- this method cannot process …Run Code Online (Sandbox Code Playgroud) 如果我有一个temp使用以下文件调用的目录:
a_file1.jpg
a_file2.jpg
b_file1.jpg
b_file2.jpg
Run Code Online (Sandbox Code Playgroud)
有可能得到这样的所有文件:
VFS.getManager().resolveFile("temp").getChildren();
Run Code Online (Sandbox Code Playgroud)
但是,我真正想做的是得到a_file1.jpg和a_file2.jpg.也许喜欢:
VFS.getManager().resolveFile("temp/a*").getChildren();
Run Code Online (Sandbox Code Playgroud)
但这引发了一个例外:
org.apache.commons.vfs.FileSystemException: Could not list the contents of "temp/a*" because it is not a folder.
Run Code Online (Sandbox Code Playgroud)
那么,有没有人知道如何基于VFS的正则表达式解析一组文件?
我想用Commons VFS2库创建一个zip文件.我知道如何在使用file前缀时复制文件但是zip没有实现文件写入和读取.
fileSystemManager.resolveFile("path comes here")zip:/some/file.zip当file.zip是一个不存在的zip文件时,我尝试路径时-method失败.我可以解析现有文件,但不存在的新文件失败.
那么如何创建新的zip文件呢?我不能使用createFile(),因为它不受支持,我无法在调用之前创建FileObject.
通常的方法是使用该resolveFile创建FileObject,然后为该对象调用createFile.
我正在尝试使用 org.apache.commons.vfs2 通过 SFTP 下载文件。问题是,密码包含“@”字符,因此这会导致 URI 被错误解析:
org.apache.commons.vfs2.FileSystemException: Expecting / to follow the hostname in URI
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?(显然我无法更改密码)。这是我正在使用的代码:
String sftpUri = "sftp://" + userName + ":" + password + "@"
+ remoteServerAddress + "/" + remoteDirectory + fileName;
String filepath = localDirectory + fileName;
File file = new File(filepath);
FileObject localFile = manager.resolveFile(file.getAbsolutePath());
FileObject remoteFile = manager.resolveFile(sftpUri, opts);
localFile.copyFrom(remoteFile, Selectors.SELECT_SELF);
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习如何使用Apache Commons VFS2.
我已经阅读了所有可以找到的文档,而且我已经熟悉了API,但仍然有一件事对我来说并不是很清楚.
Cache机制如何工作?特别是:
我没有区分缓存策略和FilesCache接口.哪个用的?
在这里的文档中说:http://wiki.apache.org/commons/VfsCacheStrategy ...有3种可能的缓存策略,每种都有详细解释.我得到了"最简单"的on_call策略,但其他两个我没有.例如 - 如果我们选择MANUAL策略,则说" 你必须使用fileObject.refresh()来刷新文件系统对象 ".但究竟是什么意思呢?这是否意味着如果我将字节写入此FileObject的FileContents,它们实际上不会被写入,直到我关闭文件对象或调用刷新?如果我有2个从同一URI解析的FileObjects并且我删除()第一个?由于缓存了文件对象,第二个的exists()方法是否仍会返回true?
当我尝试在我的机器上本地使用不同的缓存策略时,我并没有发现行为上的任何差异.它们的行为都相同,并且文件始终与FS同步(或者至少它们不是很明显).
我正在使用Apache VFS 2.1with JSch 0.1.54(今天的最新版本)来使用SFTP上传文件。
连接时系统抛出“End of IO Stream Read”,完整的堆栈为:
Caused by: com.jcraft.jsch.JSchException: Session.connect: java.io.IOException: End of IO Stream Read
at com.jcraft.jsch.Session.connect(Session.java:565)
at com.jcraft.jsch.Session.connect(Session.java:183)
at org.apache.commons.vfs2.provider.sftp.SftpClientFactory.createConnection(SftpClientFactory.java:166)
Run Code Online (Sandbox Code Playgroud)
我在这个线程中找到了解决我的问题的可能解决方案,但它直接与 JSch 一起操作。由于我使用的是 Apache VFS,我无法Session直接访问(至少我认为我不能)。
但如果可以的话,它会是这样的:
session.setConfig("kex", "diffie-hellman-group1-sha1");
Run Code Online (Sandbox Code Playgroud)
查看 Apache VFS 实现,org.apache.commons.vfs2.provider.sftp.SftpClientFactory没有找到设置此属性的方法。
如何使用 Apache VFS API 设置此配置?
日志数据:
session.setConfig("kex", "diffie-hellman-group1-sha1");
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序需要从 sftp 下载文件。我目前正在使用 apache commons-vfs2
我有一个每 1 分钟运行一次的调度程序。1. 获取远程文件列表(打开连接,获取列表,然后关闭连接) 2. 下载步骤 1 中的文件(打开连接,下载每个文件,然后关闭连接)
如何将连接保持在最低限度?有没有办法限制我与 commons-vfs2 的连接数量?
这是我的代码
private List<FileObject> getRemoteFilesList() throws FileSystemException {
FileObject[] remoteFiles;
try {
manager.init();
final @Cleanup FileObject remoteDirectoryObject = manager.resolveFile(uri, fileSystemOptions);
remoteFiles = remoteDirectoryObject.getChildren();
} finally {
manager.freeUnusedResources();
manager.close();
}
return Arrays.stream(remoteFiles)
.collect(Collectors.toList());
}
private List<File> downloadRemoteFiles(final List<FileObject> remoteFiles) {
if(remoteFiles.isEmpty()) {
return Collections.emptyList();
}
final List<File> myCollection = new ArrayList<>();
try {
manager.init();
for (final FileObject myfile : remoteFiles) {
final File localFile = downloadFile(myfile); …Run Code Online (Sandbox Code Playgroud) 我想使用存储在内存中的钱包而不是将钱包存储在磁盘上来连接到Oracle数据库。
我尝试使用Apache Common VFS读取/写入内存中的文件。钱包被写入内存(确保我什至将ramera文件夹从ram写入了磁盘)。
properties.put("oracle.net.tns_admin", "ram://my_wallet");
properties.put("oracle.net.wallet_location",
String.format("(SOURCE=(METHOD=file)(METHOD_DATA=(DIRECTORY=%s)))", "ram://my_wallet"));
Run Code Online (Sandbox Code Playgroud)
当我尝试使用这些属性建立连接时,出现错误:
java.sql.SQLRecoverableException: IO Error: could not resolve the connect identifier DB_1222
PS:如果将钱包放在磁盘上,我的代码可以正常工作。
我什至都去了Google第5页,但没有答案...我包括以下内容(我已经检查过战争,而且也在那里):
commons-collections4-4.0.jar
commons-io-2.4.jar
commons-lang3-3.3.2.jar
commons-logging-1.2.jar
commons-net-3.3.jar
commons-vfs2-2.0.jar
jackrabbit-standalone-2.8.0.jar
javax.mail-1.4.4.jar
jcifs-1.3.18.jar
jsch-0.1.51.jar
primefaces-5.0.jar
Run Code Online (Sandbox Code Playgroud)
我想1)创建一个本地文件,2)通过sftp将文件复制到我的服务器。使用正确的数据在正确的目录中本地创建文件。
我的代码被删除:
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystem;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.Selectors;
import org.apache.commons.vfs2.UserAuthenticator;
import org.apache.commons.vfs2.auth.StaticUserAuthenticator;
import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder;
import org.apache.commons.vfs2.impl.StandardFileSystemManager;
import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder;
...
public void dosftp(String data) throws FileSystemException
{
String username = "username";
String password = "password";
String fileName = "test.txt";
String localPath = "C:\\Temp\\";
String fullPath = "sftp://xxx.xxx.xxx.xxx:22/~/temp/" + fileName; …Run Code Online (Sandbox Code Playgroud)