现在我正在尝试使用 springBatch 将 http 文件(示例:“https://www.w3.org/TR/PNG/iso_8859-1.txt”)写入我的本地电脑。但无法读取文件。我的阅读器文件如下:
public FlatFileItemReader<String> reader(){
FlatFileItemReader<String> reader = new FlatFileItemReader<String>();
reader.setResource(new UrlResource("https://www.w3.org/TR/PNG/iso_8859-1.txt"));
reader.setRecordSeparatorPolicy(new RecordSeparatorPolicy() {
@Override
public boolean isEndOfRecord(String s) {
if (s.length() == 100)
return true;
return false;
}
@Override
public String postProcess(String s) {
return s;
}
@Override
public String preProcess(String s) {
return s;
}
});
return reader;
}
我正在从输入中读取 100 个长度的块并将其传递给编写器。但我收到此错误:
org.springframework.batch.item.file.FlatFileParseException: Unexpected end of file before record complete
at org.springframework.batch.item.file.FlatFileItemReader.applyRecordSeparatorPolicy(FlatFileItemReader.java:303) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.item.file.FlatFileItemReader.readLine(FlatFileItemReader.java:220) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.item.file.FlatFileItemReader.doRead(FlatFileItemReader.java:178) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
...
如何从 http 读取完整的 .txt 文件并处理并将其写入所需位置?
另外,如果我将视频文件而不是 txt 文件传递给阅读器怎么办(在这种情况下应该是什么 FlatFileItemReader< ??? > 类型?