我正在使用SMBJ读取sbm文件,虽然一切正常,但它抛出了
com.hierynomus.protocol.transport.TransportException: java.io.EOFException: EOF while reading packet我不明白为什么,它似乎能正确地关闭所有的东西。我将以下代码与try with resource一起使用:
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;
}发布于 2018-08-14 22:21:41
SmbClient本身也是Closeable。不要忘记关闭它,以确保没有资源处于打开状态。
https://stackoverflow.com/questions/51823870
复制相似问题