我有一个应用程序需要从 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) 我正在尝试从多个 xsd 文件生成 java 类。但我收到这个错误。
org.xml.sax.SAXParseException; ...“somelement”已定义
我认为这是由于常见类型包含多次。
如何使用maven生成java类?
我的目录中有以下架构:
xsd:
示例_QualifyRS.xsd
<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.002" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
<xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/>
<xs:include schemaLocation="EXAMPLE_Peble_CommonTypes.xsd"/>
<xs:element name="someelement">...</xs:element>
Run Code Online (Sandbox Code Playgroud)
示例_Peble_CommonTypes.xsd
<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.000" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
Run Code Online (Sandbox Code Playgroud)
示例_QualifyRQ.xsd
<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.001" id="EXAMPLE2016.1">
<xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
<xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/>
<xs:include schemaLocation="EXAMPLE_Peble_CommonTypes.xsd"/>
<xs:element name="someelement">...</xs:element>
Run Code Online (Sandbox Code Playgroud)
这是我在 Maven 中生成类的方法
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>example-schema</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<xsdPathWithinArtifact>xsd</xsdPathWithinArtifact>
<addGeneratedAnnotation>true</addGeneratedAnnotation>
<laxSchemaValidation>true</laxSchemaValidation>
<laxSchemaValidation>true</laxSchemaValidation>
<readOnly>true</readOnly>
<verbose>true</verbose>
<sources> …
Run Code Online (Sandbox Code Playgroud)