package cn.gistack.resource.vo; import org.springframework.web.multipart.MultipartFile; import java.io.*; public class MyMultipartFile implements MultipartFile { private String contentType; private String originalFilename; private String name; private byte[] bytes; public MyMultipartFile(){} public MyMultipartFile(String name, String originalFilename, String contentType, byte[] bytes){ this.bytes = bytes; this.name = name; this.originalFilename = originalFilename; this.contentType = contentType; } @Override public String getName() { return this.name; } @Override public String getOriginalFilename() { return this.originalFilename; } @Override public String getContentType() { return this.contentType; } @Override public boolean isEmpty() { return this.bytes == null || this.bytes.length == 0; } @Override public long getSize() { return this.bytes.length; } @Override public byte[] getBytes() throws IOException { return this.bytes; } @Override public InputStream getInputStream() throws IOException { return new ByteArrayInputStream(this.bytes); } @Override @SuppressWarnings("resource") public void transferTo(File dest) throws IOException, IllegalStateException { new FileOutputStream(dest).write(bytes); } }