将 java.io.InputStream 对象写入 smb 文件

Write java.io.InputStream object to smb file

我的一个 Java 实用程序 class(PGP 加密实用程序)读取 java.io.File(加密格式)并将其转换为 java.io.InputStream 对象(基本上解密文件并在方法末尾转换为 java.io.InputStream 对象) 我无法修改实用程序 class,因为它在整个应用程序中使用。 我需要将此对象写入一个 smb 文件到需要密码身份验证的共享路径。我如何将 java.io.InputStream 转换为 smb 文件并将其写入共享路径

1) 可以用jcifs吗? 2) 如果可能,我们有示例程序吗?

两个普通File对象的写入过程没有区别。

final SmbFile destFile = ... //Depends on how you init SmbFile object

InputStream inputStream = ... // your InputStream with data
OutputStream outputStream = null;
try {
    outputStream = destFile.getOutputStream();

    byte[] buf = new byte[STREAM_BUFFER_SIZE];
    int read;
    while ((read = inputStream.read(buf)) > -1) {
        outputStream.write(buf, 0, read);
    }
    outputStream.flush();
} finally {
    if (inputStream != null)
        inputStream.close();
    if (outputStream != null)
        outputStream.close();
}
InputStream fileInputStream // already filled
File newFile = diskShare.openFile(fullFileName, EnumSet.of(AccessMask.FILE_WRITE_DATA), null, SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OVERWRITE_IF, null);
            OutputStream oStream = newFile.getOutputStream();
            oStream.write(fileInputStream.readAllBytes());
            oStream.close();