1 16 package org.apache.myfaces.custom.fileupload; 17 18 import org.apache.commons.fileupload.FileItem; 19 20 import java.io.ByteArrayInputStream ; 21 import java.io.IOException ; 22 import java.io.InputStream ; 23 24 25 43 public class UploadedFileDefaultFileImpl extends UploadedFileDefaultImplBase 44 { 45 private transient FileItem fileItem = null; 46 47 53 54 55 public UploadedFileDefaultFileImpl(FileItem fileItem) throws IOException 56 { 57 super(fileItem.getName(), fileItem.getContentType()); 58 this.fileItem = fileItem; 59 } 60 61 62 67 public byte[] getBytes() throws IOException 68 { 69 byte[] bytes = new byte[(int)getSize()]; 70 if (fileItem != null) fileItem.getInputStream().read(bytes); 71 return bytes; 72 } 73 74 75 81 public InputStream getInputStream() throws IOException 82 { 83 return fileItem != null 84 ? fileItem.getInputStream() 85 : new ByteArrayInputStream (new byte[0]); 86 } 87 88 89 93 public long getSize() 94 { 95 return fileItem != null ? fileItem.getSize() : 0; 96 } 97 } 98 | Popular Tags |