我正在使用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;
}
答案 0 :(得分:1)
SmbClient本身也是Closeable
。不要忘记关闭它,以确保没有任何资源处于打开状态。