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 46 public class UploadedFileDefaultMemoryImpl extends UploadedFileDefaultImplBase 47 { 48 49 private byte[] bytes; 50 51 52 public UploadedFileDefaultMemoryImpl(FileItem fileItem) throws IOException 53 { 54 super(fileItem.getName(), fileItem.getContentType()); 55 int sizeInBytes = (int)fileItem.getSize(); 56 bytes = new byte[sizeInBytes]; 57 fileItem.getInputStream().read(bytes); 58 59 66 } 67 68 69 74 public byte[] getBytes() 75 { 76 return bytes; 77 } 78 79 80 86 public InputStream getInputStream() throws IOException 87 { 88 return new ByteArrayInputStream ( bytes ); 89 } 90 91 92 96 public long getSize() { 97 if( bytes == null ) 98 return 0; 99 return bytes.length; 100 } 101 } 102 | Popular Tags |