package com.seer.teach.openapi.uitl;

import org.springframework.web.multipart.MultipartFile;
import java.io.*;

public class Base64DecodedMultipartFile implements MultipartFile {

    private byte[] fileContent;

    public Base64DecodedMultipartFile(byte[] fileContent) {
        this.fileContent = fileContent;
    }

    @Override
    public String getName() {
        return System.currentTimeMillis() + "";
    }

    @Override
    public String getOriginalFilename() {
        return this.getName() + ".png";
    }

    @Override
    public String getContentType() {
        return "image/png";
    }

    @Override
    public boolean isEmpty() {
        return fileContent == null || fileContent.length == 0;
    }

    @Override
    public long getSize() {
        return fileContent.length;
    }

    @Override
    public byte[] getBytes() {
        return fileContent;
    }

    @Override
    public InputStream getInputStream() {
        return new ByteArrayInputStream(fileContent);
    }

    @Override
    public void transferTo(File dest) throws IOException, IllegalStateException {
        new FileOutputStream(dest).write(fileContent);
    }
}
