package com.atlassian.bitbucket.mesh.git.hook;

import com.google.common.io.LineProcessor;
import org.apache.commons.io.input.NullInputStream;

import javax.annotation.Nonnull;
import java.io.InputStream;

import static java.util.Objects.requireNonNull;

class EmptyHookStdin implements HookStdin {

    static final EmptyHookStdin INSTANCE = new EmptyHookStdin();

    private EmptyHookStdin() {
    }

    @Override
    public boolean isReleased() {
        return false;
    }

    @Nonnull
    @Override
    public InputStream open() {
        return new NullInputStream();
    }

    @Nonnull
    @Override
    public String read() {
        return "";
    }

    @Override
    public <T> T readLines(@Nonnull LineProcessor<T> processor) {
        return requireNonNull(processor, "processor").getResult();
    }

    @Override
    public void release() {
    }

    @Override
    public long size() {
        return 0L;
    }
}
