java - SMBJ 抛出传输/eof 异常
问题描述
我正在利用 SMBJ 读取 sbm 文件,虽然一切正常,但它正在抛出,
com.hierynomus.protocol.transport.TransportException: java.io.EOFException: EOF while reading packet
我不明白为什么,它似乎正在正确关闭所有内容。我将以下代码与资源一起使用:
try (File f = Smb.open(filename)) {
do my work with the file
}
当我处理完文件后,我调用了 releaseShare 方法,我看到很多注销会话,并在日志中注销嵌套会话消息.. 然而,这似乎并不重要,它看起来仍然像图书馆认为会话/共享仍处于打开状态,当它在 10 或 15 分钟后对其进行 ping 操作时,会引发异常......这似乎并没有伤害任何东西,就程序的工作而言,但我想摆脱错误...我没有正确关闭/处理什么?
public static DiskShare getShare() throws Exception
{
if(share == null){
SmbConfig cfg = SmbConfig.builder().withDfsEnabled(true).build();
SMBClient client = new SMBClient(cfg);
Log.info("CREATE SHARE");
connection = client.connect(sambaIP);
session = connection.authenticate(new AuthenticationContext(sambaUsername, sambaPass.toCharArray(), sambaDomain));
share = (DiskShare) session.connectShare(sambaSharedName);
}
return(share);
}
public static File open(String filename) throws Exception{
getShare();
Set<SMB2ShareAccess> s = new HashSet<>();
s.add(SMB2ShareAccess.ALL.iterator().next());
filename = filename.replace("//path base to ignore/","");
return(share.openFile(filename, EnumSet.of(AccessMask.GENERIC_READ), null, s, SMB2CreateDisposition.FILE_OPEN, null));
}
public static void releaseShare() throws Exception{
share.close();
session.close();
connection.close();
share = null;
session = null;
connection = null;
}
解决方案
SmbClient 本身也是Closeable
. 不要忘记关闭它以确保没有任何资源处于打开状态。
推荐阅读
- r - 用希腊(即 LaTeX)符号替换图例标签/文本
- python - Pandas 以特殊字符分隔的分组和求和数据列
- javascript - Google App Script 中是否有不同的 Javascript 对象?
- javascript - 用鼠标单击捕获元素后取消放置事件
- javascript - 如果tinymce.get()中的id如何触发类而不是
- c# - Entity Framework Core 3.1 嵌套集合删除对象 Linq 表达式失败
- amazon-web-services - AWS 环境变量替换
- react-native - 用户导航到新屏幕时组件未卸载
- azure-devops - 在 Azure DevOps 中开始新构建时可以知道更新的文件
- vue.js - 如何提供要替换的组件
与属性?