将远程文件流式传输到文件对象
问题描述:
如果有人知道如何将远程文件直接流式传输到文件对象中,那么不需要将文件临时存储在计算机上,这将不胜感激! 直到现在我将文件从远程IOS设备如下(使用net.schmizz.sshj)复制:将远程文件流式传输到文件对象
SSHClient ssh = new SSHClient();
ssh.addHostKeyVerifier(fingerprint);
ssh.connect(ip);
try {
ssh.authPassword("username", "userpassword".toCharArray());
ssh.newSCPFileTransfer().download(fileRemote, new FileSystemFile(fileLocal));
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
ssh.disconnect();
}
如果有任何人谁是感兴趣的解决方案的代码:
由于在他的回答中提到的Nutlike最好使用InMemoryDestFile
。 因此,创建下面的类:
class MyInMemoryDestFile extends InMemoryDestFile {
public ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@Override
public ByteArrayOutputStream getOutputStream() throws IOException {
return this.outputStream;
}
}
...在你的方法,其中在执行下载操作创建新类的实例:
MyInMemoryDestFile a = new StreamingInMemoryDestFile();
和访问的OutputStream:
ssh.newSCPFileTransfer().download(remoteFile, a);
a.getOutputStream().toByteArray();
最好的问候