リモートファイルをファイルオブジェクトに直接ストリーミングする簡単な方法を知っている人がいる場合は、ファイルを一時的にコンピュータに保存する必要はありません。これまで、次のようにリモート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();
出力ストリームにアクセスします。
ssh.newSCPFileTransfer().download(remoteFile, a);
a.getOutputStream().toByteArray();
よろしくお願いします