@Override public MultiFileImporterImpl createImporter(final ImportEventListener builder) { return new MultiFileImporterImpl((SpecificationListBuilder) builder, this.factoryLoader); }
@Override public MultiFileImporter importAny(final List<Path> paths) { for (final Path path : paths) { final File file = path.toFile(); if (file.exists()) { if (file.isDirectory()) { importRecursiveDir(path, ALL_RECURSIVE_GLOB); } else { importFile(RealFileInput.forPath(path)); } } else { LOG.warning(() -> "No such input file or directory \"" + path.toString() + "\". Skipping."); } } return this; }
@Override public MultiFileImporterImpl importFile(final InputFile file) { final int itemCountBefore = this.specItemBuilder.getItemCount(); createImporter(file, this.specItemBuilder).runImport(); final int itemCountImported = this.specItemBuilder.getItemCount() - itemCountBefore; LOG.fine(() -> "Imported " + itemCountImported + " items from '" + file + "'."); return this; }
@Override public MultiFileImporter importAny(final List<Path> paths) { for (final Path path : paths) { final File file = path.toFile(); if (file.exists()) { if (file.isDirectory()) { importRecursiveDir(path, ALL_RECURSIVE_GLOB); } else { importFile(RealFileInput.forPath(path)); } } else { LOG.warning(() -> "No such input file or directory \"" + path.toString() + "\". Skipping."); } } return this; }
@Override public MultiFileImporter importRecursiveDir(final Path dir, final String glob) { final PathMatcher matcher = dir.getFileSystem().getPathMatcher("glob:" + glob); final AtomicInteger fileCount = new AtomicInteger(0); final int itemCountBefore = this.specItemBuilder.getItemCount(); try (Stream<Path> fileStream = Files.walk(dir)) { fileStream.filter(path -> !path.toFile().isDirectory()) // .filter(matcher::matches) // .map(path -> RealFileInput.forPath(path, DEFAULT_CHARSET)) .filter(this.factoryLoader::supportsFile) .map(file -> createImporter(file, this.specItemBuilder)).forEach(importer -> { importer.runImport(); fileCount.incrementAndGet(); }); } catch (final IOException e) { throw new ImporterException("Error walking directory " + dir, e); } final int itemCountImported = this.specItemBuilder.getItemCount() - itemCountBefore; LOG.fine(() -> "Imported " + fileCount + " files containing " + itemCountImported + " items from '" + dir + "'."); return this; }
@Override public MultiFileImporterImpl importFile(final InputFile file) { final int itemCountBefore = this.specItemBuilder.getItemCount(); createImporter(file, this.specItemBuilder).runImport(); final int itemCountImported = this.specItemBuilder.getItemCount() - itemCountBefore; LOG.fine(() -> "Imported " + itemCountImported + " items from '" + file + "'."); return this; }
@Override public MultiFileImporterImpl createImporter(final ImportEventListener builder) { return new MultiFileImporterImpl((SpecificationListBuilder) builder, this.factoryLoader); }
@Override public MultiFileImporter importRecursiveDir(final Path dir, final String glob) { final PathMatcher matcher = dir.getFileSystem().getPathMatcher("glob:" + glob); final AtomicInteger fileCount = new AtomicInteger(0); final int itemCountBefore = this.specItemBuilder.getItemCount(); try (Stream<Path> fileStream = Files.walk(dir)) { fileStream.filter(path -> !path.toFile().isDirectory()) // .filter(matcher::matches) // .map(path -> RealFileInput.forPath(path, DEFAULT_CHARSET)) .filter(this.factoryLoader::supportsFile) .map(file -> createImporter(file, this.specItemBuilder)).forEach(importer -> { importer.runImport(); fileCount.incrementAndGet(); }); } catch (final IOException e) { throw new ImporterException("Error walking directory " + dir, e); } final int itemCountImported = this.specItemBuilder.getItemCount() - itemCountBefore; LOG.fine(() -> "Imported " + fileCount + " files containing " + itemCountImported + " items from '" + dir + "'."); return this; }