Search in sources :

Example 1 with Builder

use of org.sirix.fs.HierarchyFileVisitor.Builder in project sirix by sirixdb.

the class FileHierarchyWalker method parseDir.

/**
 * Parse a directory and create a simple XML representation.
 *
 * @param path path to directory from which to shredder all content into sirix
 * @param database sirix {@IDatabase} to shred into
 * @param visitor an optional visitor
 * @throws SirixException if any sirix operation fails
 * @throws IOException if an I/O error occurs
 * @throws NullPointerException if one of the arguments is {@code null}
 */
public static Map<Path, org.sirix.fs.FileSystemPath> parseDir(final Path path, final Database database, Optional<Visitor<XdmNodeWriteTrx>> visitor) throws SirixException, IOException {
    checkNotNull(visitor);
    checkNotNull(path);
    try (final ResourceManager resource = checkNotNull(database).getResourceManager(new ResourceManagerConfiguration.Builder("shredded").build());
        final XdmNodeWriteTrx wtx = resource.beginNodeWriteTrx()) {
        final Builder builder = new Builder(wtx);
        if (visitor.isPresent()) {
            builder.setVisitor(visitor.get());
        }
        Map<Path, org.sirix.fs.FileSystemPath> index = Collections.emptyMap();
        try (final HierarchyFileVisitor fileVisitor = HierarchyFileVisitor.getInstance(builder)) {
            Files.walkFileTree(path, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, fileVisitor);
            index = fileVisitor.getIndex();
        }
        return index;
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Path(java.nio.file.Path) Builder(org.sirix.fs.HierarchyFileVisitor.Builder) ResourceManager(org.sirix.api.ResourceManager)

Aggregations

Path (java.nio.file.Path)1 ResourceManager (org.sirix.api.ResourceManager)1 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)1 Builder (org.sirix.fs.HierarchyFileVisitor.Builder)1