本文整理汇总了Java中net.schmizz.sshj.xfer.InMemoryDestFile类的典型用法代码示例。如果您正苦于以下问题:Java InMemoryDestFile类的具体用法?Java InMemoryDestFile怎么用?Java InMemoryDestFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InMemoryDestFile类属于net.schmizz.sshj.xfer包,在下文中一共展示了InMemoryDestFile类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readTextFile
import net.schmizz.sshj.xfer.InMemoryDestFile; //导入依赖的package包/类
/**
* Reads the contents of a file on the remote node, assuming UTF-8 encoding
* @param targetPath the full path to the file on the host
* @return the contents of the file
*/
public String readTextFile(String remotePath) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
InMemoryDestFile dest = new InMemoryDestFile() {
@Override public OutputStream getOutputStream() throws IOException {
return out;
}
};
client.newSCPFileTransfer().download(remotePath, dest);
return new String(out.toByteArray(), Charset.forName("UTF-8"));
}
示例2: downloadAndSavePrivateKey
import net.schmizz.sshj.xfer.InMemoryDestFile; //导入依赖的package包/类
private void downloadAndSavePrivateKey(SSHClient ssh, InstanceMetaData gwInstance) throws IOException {
ByteArrayOutputStream cert = new ByteArrayOutputStream();
ssh.newSCPFileTransfer().download("/tmp/cluster.pem", new InMemoryDestFile() {
@Override
public OutputStream getOutputStream() {
return cert;
}
});
cert.close();
InstanceMetaData metaData = instanceMetaDataRepository.findOne(gwInstance.getId());
metaData.setServerCert(BaseEncoding.base64().encode(cert.toByteArray()));
instanceMetaDataRepository.save(metaData);
}