Hi,
providing the following case, an unjustified
FileNotFoundExeption is thrown while loading MIB modules.
Given the following directory structure
dirA:
mib1
mib2
dirB:
mib3
the following code rises the Exception.
String[] paths = {"dirA", "dirB"};
MibOps mibOps = new MibOps(paths);
mibOps.loadMib("mib2");
I tracked the error down to the
MibFileHandlerClass.searchFiles() method. The reason
is, that the for loop iterating over the single
directories A and B is continued to dirB even though
mib2 was found in dirA and thus fileName evaluatied to
mib2. As a consequence the
MibFileHandlerClass.correctFile() method tries to read
the file dirB/mib2 which evidently does not exist.
I am going to attach a path to the
MibFileHandlerClass.searchFiles() method. Hope I could
help.
public static String searchFiles(String[] path, String
nameToSearch) {
String fileName = null;
for (int i = 0; i < path.length; i++) {
// Look for "mib.files" file
File file = new File(path[i] +
File.separator + MIB_FILES);
if (file.exists()) {
fileName = searchMibFiles(file,
nameToSearch);
if (!correctFile(path[i], fileName, nameToSearch))
return fileName;
}
// If not found, look for a file with the
same name
file = new File(path[i] + File.separator +
nameToSearch);
if (file.exists()) {
fileName = file.getName();
if (!correctFile(path[i], fileName, nameToSearch))
return fileName;
}
// If not found, look for a "similar" name
fileName = regexOnFiles(path[i], nameToSearch);
if (fileName != null) {
return fileName;
}
}
return fileName;
}
Regards,
Jakob
Logged In: YES
user_id=1298949
Hi,
I am afraid I had a typo in my patch above.
The negations at the 'if' clauses are wrong.
The correct patch below. Sorry.
public static String searchFiles(String[] path, String
nameToSearch) {
String fileName = null;
for (int i = 0; i < path.length; i++) {
// Look for "mib.files" file
File file = new File(path[i] +
File.separator + MIB_FILES);
if (file.exists()) {
fileName = searchMibFiles(file,
nameToSearch);
if (correctFile(path[i], fileName, nameToSearch))
return fileName;
}
// If not found, look for a file with the
same name
file = new File(path[i] + File.separator +
nameToSearch);
if (file.exists()) {
fileName = file.getName();
if (correctFile(path[i], fileName, nameToSearch))
return fileName;
}
// If not found, look for a "similar" name
fileName = regexOnFiles(path[i], nameToSearch);
if (fileName != null) {
return fileName;
}
}
return fileName;
}