如果有人知道如何将远程文件直接流式传输到文件对象的快速方法,那么没有必要将文件临时存储在计算机上,我们将不胜感激!到目前为止,我从远程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();
}
Run Code Online (Sandbox Code Playgroud)
如果有人对解决方案的代码感兴趣:
正如Nutlike在回答中提到的那样,最好使用它InMemoryDestFile.所以创建以下类:
class MyInMemoryDestFile extends InMemoryDestFile {
public ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@Override
public ByteArrayOutputStream getOutputStream() throws IOException {
return this.outputStream;
}
}
Run Code Online (Sandbox Code Playgroud)
...在执行下载操作的方法中,创建新类的实例:
MyInMemoryDestFile a = new StreamingInMemoryDestFile();
Run Code Online (Sandbox Code Playgroud)
并访问输出流:
ssh.newSCPFileTransfer().download(remoteFile, a);
a.getOutputStream().toByteArray();
Run Code Online (Sandbox Code Playgroud)
最好的祝福
使用InMemoryDestFile而不是FileSystemFile还不够吗?
\n\n编辑:\xe2\x80\xa6,然后使用getOutputStream()访问\'文件\'\xe2\x80\xa6
\n| 归档时间: |
|
| 查看次数: |
1051 次 |
| 最近记录: |