The FileDataSource class implements a simple DataSource object that encapsulates a file. It provides data typing services via a FileTypeMap object. FileDataSource Typing Semantics The FileDataSource class delegates data typing of files to an object subclassed from the FileTypeMap cla
| 39 | * @see javax.activation.MimetypesFileTypeMap |
| 40 | */ |
| 41 | public class FileDataSource implements DataSource { |
| 42 | |
| 43 | // keep track of original 'ref' passed in, non-null |
| 44 | // one indicated which was passed in: |
| 45 | private File _file = null; |
| 46 | private FileTypeMap typeMap = null; |
| 47 | |
| 48 | /** |
| 49 | * Creates a FileDataSource from a File object. <i>Note: |
| 50 | * The file will not actually be opened until a method is |
| 51 | * called that requires the file to be opened.</i> |
| 52 | * |
| 53 | * @param file the file |
| 54 | */ |
| 55 | public FileDataSource(File file) { |
| 56 | _file = file; // save the file Object... |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Creates a FileDataSource from |
| 61 | * the specified path name. <i>Note: |
| 62 | * The file will not actually be opened until a method is |
| 63 | * called that requires the file to be opened.</i> |
| 64 | * |
| 65 | * @param name the system-dependent file name. |
| 66 | */ |
| 67 | public FileDataSource(String name) { |
| 68 | this(new File(name)); // use the file constructor |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * This method will return an InputStream representing the |
| 73 | * the data and will throw an IOException if it can |
| 74 | * not do so. This method will return a new |
| 75 | * instance of InputStream with each invocation. |
| 76 | * |
| 77 | * @return an InputStream |
| 78 | */ |
| 79 | public InputStream getInputStream() throws IOException { |
| 80 | return new FileInputStream(_file); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * This method will return an OutputStream representing the |
| 85 | * the data and will throw an IOException if it can |
| 86 | * not do so. This method will return a new instance of |
| 87 | * OutputStream with each invocation. |
| 88 | * |
| 89 | * @return an OutputStream |
| 90 | */ |
| 91 | public OutputStream getOutputStream() throws IOException { |
| 92 | return new FileOutputStream(_file); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * This method returns the MIME type of the data in the form of a |
| 97 | * string. This method uses the currently installed FileTypeMap. If |
| 98 | * there is no FileTypeMap explictly set, the FileDataSource will |
nothing calls this directly
no outgoing calls
no test coverage detected