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

ru.yandex.qatools.allure.data.io.AttachmentReader Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package ru.yandex.qatools.allure.data.io;

import com.google.inject.Inject;
import ru.yandex.qatools.allure.config.AllureConfig;
import ru.yandex.qatools.allure.data.AttachmentInfo;

import java.io.File;
import java.util.Iterator;

import static ru.yandex.qatools.allure.commons.AllureFileUtils.listFilesByRegex;

/**
 * @author Dmitry Baev [email protected]
 *         Date: 19.02.15
 */
public class AttachmentReader implements Reader {

    private Iterator iterator;

    @Inject
    public AttachmentReader(@ResultDirectories File... inputDirectories) {
        AllureConfig config = AllureConfig.newInstance();
        iterator = listFilesByRegex(
                config.getAttachmentFileRegex(),
                inputDirectories
        ).iterator();
    }

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

            @Override
            public AttachmentInfo next() {
                if (!hasNext()) {
                    return null;
                }

                File next = iterator.next();
                AttachmentInfo info = new AttachmentInfo();
                info.setName(next.getName());
                info.setPath(next.getAbsolutePath());
                return info;
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException();
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy