1 23 24 package org.dbforms.util; 25 26 import org.apache.commons.fileupload.FileItem; 27 28 import java.io.File ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 32 33 34 41 public class FileHolder implements java.io.Serializable { 42 private FileItem fileItem; 44 private String fileName; 45 46 58 public FileHolder(String fileName, 59 FileItem fileItem) 60 throws IOException , IllegalArgumentException { 61 this.fileName = fileName; 62 this.fileItem = fileItem; 63 } 64 65 70 public String getContentType() { 71 return fileItem.getContentType(); 72 } 73 74 75 87 public int getFileLength() { 88 return (int) fileItem.getSize(); 89 } 90 91 92 97 public void setFileName(String fileName) { 98 this.fileName = fileName; 99 } 100 101 102 112 public String getFileName() { 113 return fileName; 114 } 115 116 117 124 public InputStream getInputStreamFromBuffer() throws IOException { 125 return fileItem.getInputStream(); 126 } 127 128 129 137 public void writeBufferToFile(File fileOrDirectory) 138 throws IOException { 139 if (fileName != null) { 141 File file; 143 144 if (fileOrDirectory.isDirectory()) { 145 file = new File (fileOrDirectory, fileName); 148 } else { 149 file = fileOrDirectory; 152 } 153 154 try { 155 fileItem.write(file); 156 } catch (Exception e) { 157 throw new IOException (e.getMessage()); 158 } 159 } 160 } 161 } 162 | Popular Tags |