java – 将远程文件流式传输到文件对象中
发布时间:2020-12-14 19:34:07 所属栏目:Java 来源:网络整理
导读:如果有人知道如何将远程文件直接流式传输到文件对象的快速方法,那么没有必要将文件临时存储在计算机上,我们将不胜感激! 到目前为止,我从远程ios设备复制文件如下(使用net.schmizz.sshj): SSHClient ssh = new SSHClient();ssh.addHostKeyVerifier(fingerpr
如果有人知道如何将远程文件直接流式传输到文件对象的快速方法,那么没有必要将文件临时存储在计算机上,我们将不胜感激!
到目前为止,我从远程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(); 最好的祝福 解决方法
使用
InMemoryDestFile而不是
FileSystemFile是不够的?
编辑:…然后使用getOutputStream()访问’文件’… (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |