package com.atlassian.stash.internal.rest.avatar;

import com.atlassian.plugins.rest.common.multipart.FilePart;
import com.atlassian.bitbucket.avatar.AbstractAvatarSupplier;

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

import static com.google.common.base.Preconditions.checkNotNull;

/**
 * @since 2.12
 */
public class FilePartAvatarSupplier extends AbstractAvatarSupplier {

    private final FilePart file;

    public FilePartAvatarSupplier(@Nonnull FilePart file) {
        super(checkNotNull(file, "file").getContentType());

        this.file = file;
    }

    @Nonnull
    @Override
    public InputStream open() throws IOException {
        return file.getInputStream();
    }
}
