package com.atlassian.bitbucket.mesh.git.builder.lstree;

import com.atlassian.bitbucket.mesh.process.handler.AbstractLineStdioHandler;
import com.atlassian.bitbucket.mesh.process.handler.LineDecoder;

import javax.annotation.Nonnull;
import java.nio.charset.StandardCharsets;

public class ModeLsTreeStdioHandler extends AbstractLineStdioHandler<String> {

    private String mode;

    public ModeLsTreeStdioHandler() {
        //Modes are always 6 characters or less
        super(StandardCharsets.UTF_8, LineDecoder.Mode.NULL, 6);
    }

    @Nonnull
    @Override
    public String getResult() {
        return mode;
    }

    @Override
    protected boolean onStdout(@Nonnull String line, boolean truncated) {
        mode = line;

        //No matter what, we get all the output we want to handle on the first line
        return false;
    }
}
