Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java RemoteFileTemplate读取的文件不完整?_Java_Spring_Spring Integration - Fatal编程技术网

Java RemoteFileTemplate读取的文件不完整?

Java RemoteFileTemplate读取的文件不完整?,java,spring,spring-integration,Java,Spring,Spring Integration,我进行了以下测试,将文件上载到嵌入式ApacheFTP服务器,然后检查文件是否正确上载 @Test public void testUploadFile() { String fileName = "test.txt"; ftpUploader.upload("/data/" + fileName); RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<>(this.ftpSe

我进行了以下测试,将文件上载到嵌入式ApacheFTP服务器,然后检查文件是否正确上载

@Test
public void testUploadFile() {
    String fileName = "test.txt";
    ftpUploader.upload("/data/" + fileName);
    RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<>(this.ftpSessionFactory);
    FTPFile[] files = template.execute(session -> session.list(fileName));
    assertThat(files).hasSize(1);
    assertThat(files[0].getSize()).isEqualTo(FILE_CONTENT_SIZE);
}
@测试
public void testUploadFile(){
字符串fileName=“test.txt”;
ftpUploader.upload(“/data/”+文件名);
RemoteFileTemplate=新的RemoteFileTemplate(this.ftpSessionFactory);
FTPFile[]files=template.execute(session->session.list(fileName));
资产(文件).hasSize(1);
assertThat(文件[0].getSize()).isEqualTo(文件内容大小);
}
我正在使用Spring集成。如果文件存在且大小正确,则通过RemoteFileTemplate I cehck。如果我在IDE中执行这个测试,它就可以正常工作。包括所有测试的maven构建也可以工作。然而,在Jenkins服务器上,第二个断言失败

org.junit.ComparisonFailure: expected:<2[318796]L> but was:<2[290518]L>
org.junit.ComparisonFailure:应为:但为:
原因可能是什么?模板是否下载文件,即使文件未完全上载?事实上,这种情况不应该发生,因为ftpUploader会在文件仍然被写入的情况下,向文件中追加end.writing。FtpUpload如下所示

 @MessagingGateway
public interface FtpUpload {

    @Gateway(requestChannel = "ftpUploadChannel")
    void upload(String fileName);
}

@Bean
IntegrationFlow upload() {
    return IntegrationFlows.from("ftpUploadChannel")
            .<String, File>transform(fileName -> new File(this.getClass().getResource(fileName).getFile()))
            .handle(Ftp.outboundAdapter(ftpSessionFactory())
                            .remoteDirectory(ftpRemoteDir)
                            .autoCreateDirectory(true)
                            .useTemporaryFileName(true)
            )
            .get();
}
@MessagingGateway
公共接口加载{
@网关(requestChannel=“ftpUploadChannel”)
无效上传(字符串文件名);
}
@豆子
集成流上载(){
返回IntegrationFlows.from(“ftpUploadChannel”)
.transform(文件名->新文件(此.getClass().getResource(文件名).getFile())
.handle(Ftp.outboundAdapter(ftpSessionFactory())
.remoteDirectory(ftpRemoteDir)
.autoCreateDirectory(true)
.useTemporaryFileName(true)
)
.get();
}

默认情况下,大多数FTP客户端使用
ASCII
模式传输文件。在此模式下,换行符将被更改。因此,在您的情况下,在不同环境中运行时,文件大小会发生变化。最可能的原因是换行符在一个环境中更改。

Jenkins是否使用与您的开发人员桌面相同的操作系统?将文件上载到ftp可能会更改换行符。是的,这可能是问题所在。感谢提示预期大小和实际大小之间的差异就是文件的行数。谢谢@Longhaig think,@longhua,最好从你的团队中形成一个答案,并用这个解决方案结束其他所有人的线索。