126.7. 例子
以下示例演示了如何从 SMB 文件共享中轮询所有文件并读取这些文件的内容:
private void process(Exchange exchange) throws IOException {
final File file = exchange.getMessage().getBody(File.class);
try (InputStream inputStream = file.getInputStream()) {
LOG.debug("Read exchange: {}, with contents: {}", file.getFileInformation(), new String(inputStream.readAllBytes()));
}
}
public void configure() {
fromF("smb:%s/%s?username=%s&password=%s&path=/", service.address(), service.shareName(), service.userName(), service.password())
.process(this::process)
.to("mock:result");
}
注意
提供的 File 对象不是 java.io.File 实例,而是 com.hierynomus.smbj.share.File 实例。