SMBJ 抛出 transport/eof 异常
SMBJ throwing transport/eof exceptions
我正在利用 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 方法,我在日志中看到大量注销会话和嵌套会话消息。然而,这似乎并不重要,图书馆似乎仍然认为 session/share 仍处于打开状态,当它在 10 或 15 分钟后对它执行 ping 操作时,会抛出异常……就程序运行而言,这似乎没有任何影响,但是我想消除错误...我有什么不正确的 closing/handling?
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
。不要忘记关闭它以确保没有资源处于打开状态。
我正在利用 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 方法,我在日志中看到大量注销会话和嵌套会话消息。然而,这似乎并不重要,图书馆似乎仍然认为 session/share 仍处于打开状态,当它在 10 或 15 分钟后对它执行 ping 操作时,会抛出异常……就程序运行而言,这似乎没有任何影响,但是我想消除错误...我有什么不正确的 closing/handling?
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
。不要忘记关闭它以确保没有资源处于打开状态。