All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.marklogic.spark.writer.file.FileIterator Maven / Gradle / Ivy

There is a newer version: 2.4.2
Show newest version
/*
 * Copyright © 2024 MarkLogic Corporation. All Rights Reserved.
 */
package com.marklogic.spark.writer.file;

import com.marklogic.client.io.InputStreamHandle;
import com.marklogic.spark.writer.DocBuilder;
import org.apache.commons.io.IOUtils;

import java.io.Closeable;
import java.util.Iterator;
import java.util.stream.Stream;

/**
 * Exists solely to provide an implementation of {@code Closeable} so that the {@code InputStreamHandle} can be closed
 * after the corresponding document is written to MarkLogic.
 */
public class FileIterator implements Iterator, Closeable {

    private final InputStreamHandle contentHandle;
    private final Iterator iterator;

    public FileIterator(InputStreamHandle contentHandle, DocBuilder.DocumentInputs inputs) {
        this.contentHandle = contentHandle;
        this.iterator = Stream.of(inputs).iterator();
    }

    @Override
    public boolean hasNext() {
        return this.iterator.hasNext();
    }

    @Override
    public DocBuilder.DocumentInputs next() {
        return this.iterator.next();
    }

    @Override
    public void close() {
        IOUtils.closeQuietly(contentHandle);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy