package com.atlassian.stash.internal.scm.git.command.lsfiles;

import com.atlassian.bitbucket.io.LineReader;
import com.atlassian.bitbucket.io.LineReaderOutputHandler;
import com.atlassian.bitbucket.scm.CommandOutputHandler;
import com.google.common.collect.Lists;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

public class SimpleLsFilesOutputHandler extends LineReaderOutputHandler implements CommandOutputHandler<List<String>> {

    private final List<String> paths = Lists.newArrayList();

    public SimpleLsFilesOutputHandler() {
        super(StandardCharsets.UTF_8);
    }

    @Override
    public List<String> getOutput() {
        return paths;
    }

    @Override
    protected void processReader(LineReader reader) throws IOException {
        String line;
        while ((line = resetWatchdogAndReadLine(reader)) != null) {
            paths.add(line);
        }
    }
}
