void () { List<Path> templateWithDefaultExtension = new ArrayList<>(); Set<String> processedNames = new HashSet<>(); List<FileTemplateBase> children = new ArrayList<>(); try (DirectoryStream<Path> stream = Files.newDirectoryStream(templateDir, file -> !Files.isDirectory(file) && !Files.isHidden(file))) { FileTypeManager fileTypeManager = FileTypeManager.getInstance(); for (Path file : stream) { String fileName = file.getFileName().toString(); // check it here and not in filter to reuse fileName if (fileTypeManager.isFileIgnored(fileName)) { continue; } if (fileName.endsWith(TEMPLATE_EXTENSION_SUFFIX)) { templateWithDefaultExtension.add(file); } else { processedNames.add(fileName); FileTemplateBase template = addTemplateFromFile(fileName, file); if (fileName.contains(FileTemplateBase.TEMPLATE_CHILDREN_SUFFIX)) { children.add(template); } } } } catch (NoSuchFileException ignored) { } catch (IOException e) { LOG.error(e); return; } for (FileTemplateBase child : children) { String qname = getParentName(child); FileTemplateBase parent = getTemplate(qname); if (parent != null) { parent.addChild(child); } } for (Path file : templateWithDefaultExtension) { String name = file.getFileName().toString(); // cut default template extension name = name.substring(0, name.length() - TEMPLATE_EXTENSION_SUFFIX.length()); if (!processedNames.contains(name)) { addTemplateFromFile(name, file); } try { Files.delete(file); } catch (IOException e) { LOG.error(e); } } }