private void loadDirectory(String[] files, String path) throws Exception { StringBuilder currentPath = new StringBuilder(); for (int i = 0; i < files.length; i++) { if (!path.endsWith("/")) { currentPath.append(path).append("/"); } currentPath.append(files[i]); if (SingletonFSInterface.instance().isFile(new URI(currentPath.toString()))) // if it's a file { try { if (!files[i].startsWith(".")) { mibLoader.load(files[i]); } } catch (Exception e) { GlobalLogger.instance() .getApplicationLogger() .error(TextEvent.Topic.PROTOCOL, e, "ERROR : loading the MIBS files"); if (e instanceof MibLoaderException) { ((MibLoaderException) e).getLog().printTo(new PrintStream("../logs/snmpStack.log")); } } } else // if it's a directory, load it and all it's content { if (!files[i].startsWith(".")) { loadDirectory( SingletonFSInterface.instance().list(new URI(currentPath.toString())), currentPath.toString()); } } // reset currentPath currentPath.delete(0, currentPath.length()); } }
private void loadAllMibs() throws Exception { mibLoader = new MibLoader(); mibLoader.addAllDirs(new File("../conf/snmp/mibs")); // add all subDirectories to search for mib // travel through mibs repository to add all mibs loadDirectory( SingletonFSInterface.instance().list(new URI("../conf/snmp/mibs")), "../conf/snmp/mibs"); }