9

リモートファイルをファイルオブジェクトに直接ストリーミングする簡単な方法を知っている人がいる場合は、ファイルを一時的にコンピュータに保存する必要はありません。これまで、次のようにリモート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();

よろしくお願いします

4

1 に答える 1

5

FileSystemFileの代わりにInMemoryDe​​stFileを使用するだけでは不十分でしょうか?

編集:…そしてgetOutputStream()を使用して「ファイル」にアクセスします…</ p>

于 2013-02-22T10:29:13.593 に答える