package org.xbib.files;

import java.io.Closeable;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.util.Iterator;

public class WrappedDirectoryStream<T> implements DirectoryStream<T> {

    private final Closeable closeable;

    private final DirectoryStream<T> directoryStream;

    public WrappedDirectoryStream(Closeable closeable, DirectoryStream<T> directoryStream) {
        this.closeable = closeable;
        this.directoryStream = directoryStream;
    }

    @Override
    public Iterator<T> iterator() {
        return directoryStream.iterator();
    }

    @Override
    public void close() throws IOException {
        directoryStream.close();
        closeable.close();
    }
}
