daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.ByteArrayInputStream;
  2. import java.io.File;
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6.  
  7. import org.apache.logging.log4j.LogManager;
  8. import org.apache.logging.log4j.Logger;
  9. import org.springframework.web.multipart.MultipartFile;
  10.  
  11. public class BASE64DecodedMultipartFile implements MultipartFile {
  12.    
  13.     protected static final Logger log = LogManager.getLogger(BASE64DecodedMultipartFile.class);
  14.    
  15.     private byte[] imgContent;
  16.     private String fileName;
  17.     private String ext;
  18.  
  19.     public String getExt() {
  20.         return ext;
  21.     }
  22.    
  23.     @Override
  24.     public String getName() {
  25.         return fileName;
  26.     }
  27.  
  28.     @Override
  29.     public String getOriginalFilename() {
  30.         return fileName;
  31.     }
  32.  
  33.     @Override
  34.     public String getContentType() {
  35.         if(getExt() == null) {
  36.             return null;
  37.         }
  38.         return MimeTypes.getMimeType(getExt());
  39.     }
  40.  
  41.     @Override
  42.     public boolean isEmpty() {
  43.         return imgContent == null || imgContent.length == 0;
  44.     }
  45.  
  46.     @Override
  47.     public long getSize() {
  48.         return imgContent.length;
  49.     }
  50.  
  51.     @Override
  52.     public byte[] getBytes() throws IOException {
  53.         return imgContent;
  54.     }
  55.  
  56.     @Override
  57.     public InputStream getInputStream() throws IOException {
  58.         return new ByteArrayInputStream(imgContent);
  59.     }
  60.  
  61.     @Override
  62.     public void transferTo(File dest) throws IOException {
  63.         try (FileOutputStream f = new FileOutputStream(dest)) {
  64.             f.write(imgContent);
  65.         }
  66.     }
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top