1 16 package org.apache.cocoon.servlet.multipart; 17 18 import java.io.FileOutputStream ; 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.OutputStream ; 22 import java.util.Map ; 23 24 import org.apache.avalon.excalibur.io.IOUtil; 25 import org.apache.avalon.framework.activity.Disposable; 26 import org.apache.excalibur.source.ModifiableSource; 27 28 29 41 public abstract class Part implements Disposable { 42 43 private boolean disposeWithRequest = true; 44 45 46 protected Map headers; 47 48 protected Part(Map headers) { 49 this.headers = headers; 50 } 51 52 55 public Map getHeaders() { 56 return headers; 57 } 58 59 62 public abstract String getFileName(); 63 64 67 public String getUploadName(){ 68 return (String ) headers.get("filename"); 69 } 70 71 74 public abstract int getSize(); 75 76 82 public boolean isRejected() { 83 return false; 84 } 85 86 89 public String getMimeType() { 90 return (String ) headers.get("content-type"); 91 } 92 93 99 public boolean disposeWithRequest() { 100 return this.disposeWithRequest; 101 } 102 103 108 public void setDisposeWithRequest(boolean dispose) { 109 this.disposeWithRequest = dispose; 110 } 111 112 116 public abstract InputStream getInputStream() throws IOException ; 117 118 125 public void copyToSource(ModifiableSource source) throws IOException { 126 InputStream is = getInputStream(); 127 OutputStream os = source.getOutputStream(); 128 IOUtil.copy(is, os); 129 is.close(); 130 os.close(); 131 } 132 133 140 public void copyToFile(String filename) throws IOException { 141 InputStream is = getInputStream(); 142 OutputStream os = new FileOutputStream (filename); 143 IOUtil.copy(is, os); 144 is.close(); 145 os.close(); 146 } 147 148 154 public abstract void dispose(); 155 } 156 | Popular Tags |