1 3 package jodd.servlet.upload.impl; 4 5 import jodd.util.SystemUtil; 6 import jodd.servlet.upload.FileUpload; 7 import jodd.servlet.upload.MultipartRequestInputStream; 8 import jodd.servlet.upload.FileUploadFactory; 9 10 import java.io.IOException ; 11 import java.io.File ; 12 import java.io.FileOutputStream ; 13 import java.io.BufferedOutputStream ; 14 15 18 public class DiskFileUpload extends FileUpload { 19 20 protected String destFolder; 21 22 public DiskFileUpload(MultipartRequestInputStream input) { 23 super(input); 24 this.destFolder = SystemUtil.getTempDir(); 25 } 26 27 public DiskFileUpload(MultipartRequestInputStream input, String destinationFolder) { 28 super(input); 29 this.destFolder = destinationFolder; 30 } 31 32 35 public String getDestinationFolder() { 36 return destFolder; 37 } 38 39 40 43 public File getFile() { 44 return file; 45 } 46 47 protected File file; 48 49 protected void processStream() throws IOException { 50 file = new File (destFolder, header.getFileName()); 51 FileOutputStream fos = new FileOutputStream (file); 52 size = -1; 53 try { 54 size = input.copyAll(new BufferedOutputStream (fos)); 55 } finally { 56 try { 57 fos.close(); 58 } catch(Exception ex) { 59 } 61 } 62 } 63 64 66 public static class Factory implements FileUploadFactory { 67 68 public FileUpload create(MultipartRequestInputStream input) { 69 return new DiskFileUpload(input); 70 } 71 } 72 } 73 | Popular Tags |