package cn.lihongjie.coal.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;

import org.apache.commons.io.IOUtils;

import java.io.InputStream;
import java.util.*;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Base64File {

    private String fileName;

    private String base64;

    public void setData(byte[] data) {
        this.base64 = Base64.getEncoder().encodeToString(data);
    }

    public void setData(String data) {
        this.base64 = Base64.getEncoder().encodeToString(data.getBytes());
    }

    @SneakyThrows
    public void setData(InputStream is) {

        setData(IOUtils.toByteArray(is));
    }
}
