java 文件流传输_java – 将远程文件流式传输到文件对象中
如果有人知道如何將遠程文件直接流式傳輸到文件對象的快速方法,那么沒有必要將文件臨時存儲在計算機上,我們將不勝感激!
到目前為止,我從遠程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在他的回答中提到的,最好使用InMemoryDe??stFile.
所以創建以下類:
class MyInMemoryDestFile extends InMemoryDestFile {
public ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
@Override
public ByteArrayOutputStream getOutputStream() throws IOException {
return this.outputStream;
}
}
…在執行下載操作的方法中,創建新類的實例:
MyInMemoryDestFile a = new StreamingInMemoryDestFile();
并訪問輸出流:
ssh.newSCPFileTransfer().download(remoteFile, a);
a.getOutputStream().toByteArray();
最好的祝福
總結
以上是生活随笔為你收集整理的java 文件流传输_java – 将远程文件流式传输到文件对象中的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 调和平均
- 下一篇: 不完全遍历Csrss进程中的句柄表