1 21 22 27 28 package javax.activation; 29 30 import java.io.InputStream ; 31 import java.io.OutputStream ; 32 import java.io.File ; 33 import java.io.FileDescriptor ; 34 import java.io.FileNotFoundException ; 35 import java.io.FileInputStream ; 36 import java.io.FileOutputStream ; 37 import java.io.IOException ; 38 import com.sun.activation.registries.MimeTypeFile; 39 40 58 public class FileDataSource implements DataSource { 59 60 private File _file = null; 63 private FileTypeMap typeMap = null; 64 65 72 public FileDataSource(File file) { 73 _file = file; } 75 76 84 public FileDataSource(String name) { 85 this(new File (name)); } 87 88 96 public InputStream getInputStream() throws IOException { 97 return new FileInputStream (_file); 98 } 99 100 108 public OutputStream getOutputStream() throws IOException { 109 return new FileOutputStream (_file); 110 } 111 112 123 public String getContentType() { 124 if (typeMap == null) 126 return FileTypeMap.getDefaultFileTypeMap().getContentType(_file); 127 else 128 return typeMap.getContentType(_file); 129 } 130 131 138 public String getName() { 139 return _file.getName(); 140 } 141 142 146 public File getFile() { 147 return _file; 148 } 149 150 155 public void setFileTypeMap(FileTypeMap map) { 156 typeMap = map; 157 } 158 } 159 | Popular Tags |