1 16 package org.apache.cocoon.servlet.multipart; 17 18 import java.io.File ; 19 import java.io.FileInputStream ; 20 import java.io.IOException ; 21 import java.io.InputStream ; 22 import java.util.Map ; 23 24 30 public class PartOnDisk extends Part { 31 32 33 private File file = null; 34 private int size; 35 36 42 protected PartOnDisk(Map headers, File file) { 43 super(headers); 44 this.file = file; 45 46 this.file.deleteOnExit(); 48 49 this.size = (int) file.length(); 50 } 51 52 55 public String getFileName() { 56 return file.getName(); 57 } 58 59 62 public int getSize() { 63 return this.size; 64 } 65 66 69 public File getFile() { 70 return file; 71 } 72 73 78 public InputStream getInputStream() throws IOException { 79 if (this.file != null) { 80 return new FileInputStream (file); 81 } else { 82 throw new IllegalStateException ("This part has already been disposed."); 83 } 84 } 85 86 89 public String toString() { 90 return file.getPath(); 91 } 92 93 96 public void dispose() { 97 if (this.file != null) { 98 this.file.delete(); 99 this.file = null; 100 } 101 } 102 103 106 public void finalize() throws Throwable { 107 dispose(); 109 110 super.finalize(); 111 } 112 } 113 | Popular Tags |