- java.lang.Object
- 
- jakarta.activation.FileDataSource
 
- 
- All Implemented Interfaces:
- DataSource
 
 public class FileDataSource extends java.lang.Object implements DataSource 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 class. The setFileTypeMapmethod can be used to explicitly set the FileTypeMap for an instance of FileDataSource. If no FileTypeMap is set, the FileDataSource will call the FileTypeMap's getDefaultFileTypeMap method to get the System's default FileTypeMap.- See Also:
- DataSource,- FileTypeMap,- MimetypesFileTypeMap
 
- 
- 
Constructor SummaryConstructors Constructor Description FileDataSource(java.io.File file)Creates a FileDataSource from a File object.FileDataSource(java.lang.String name)Creates a FileDataSource from the specified path name.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetContentType()This method returns the MIME type of the data in the form of a string.java.io.FilegetFile()Return the File object that corresponds to this FileDataSource.java.io.InputStreamgetInputStream()This method will return an InputStream representing the the data and will throw an IOException if it can not do so.java.lang.StringgetName()Return the name of this object.java.io.OutputStreamgetOutputStream()This method will return an OutputStream representing the the data and will throw an IOException if it can not do so.voidsetFileTypeMap(FileTypeMap map)Set the FileTypeMap to use with this FileDataSource
 
- 
- 
- 
Constructor Detail- 
FileDataSourcepublic FileDataSource(java.io.File file) Creates a FileDataSource from a File object. Note: The file will not actually be opened until a method is called that requires the file to be opened.- Parameters:
- file- the file
 
 - 
FileDataSourcepublic FileDataSource(java.lang.String name) Creates a FileDataSource from the specified path name. Note: The file will not actually be opened until a method is called that requires the file to be opened.- Parameters:
- name- the system-dependent file name.
 
 
- 
 - 
Method Detail- 
getInputStreampublic java.io.InputStream getInputStream() throws java.io.IOExceptionThis method will return an InputStream representing the the data and will throw an IOException if it can not do so. This method will return a new instance of InputStream with each invocation.- Specified by:
- getInputStreamin interface- DataSource
- Returns:
- an InputStream
- Throws:
- java.io.IOException- for failures creating the InputStream
 
 - 
getOutputStreampublic java.io.OutputStream getOutputStream() throws java.io.IOExceptionThis method will return an OutputStream representing the the data and will throw an IOException if it can not do so. This method will return a new instance of OutputStream with each invocation.- Specified by:
- getOutputStreamin interface- DataSource
- Returns:
- an OutputStream
- Throws:
- java.io.IOException- for failures creating the OutputStream
 
 - 
getContentTypepublic java.lang.String getContentType() This method returns the MIME type of the data in the form of a string. This method uses the currently installed FileTypeMap. If there is no FileTypeMap explictly set, the FileDataSource will call thegetDefaultFileTypeMapmethod on FileTypeMap to acquire a default FileTypeMap. Note: By default, the FileTypeMap used will be a MimetypesFileTypeMap.- Specified by:
- getContentTypein interface- DataSource
- Returns:
- the MIME Type
- See Also:
- FileTypeMap.getDefaultFileTypeMap()
 
 - 
getNamepublic java.lang.String getName() Return the name of this object. The FileDataSource will return the file name of the object.- Specified by:
- getNamein interface- DataSource
- Returns:
- the name of the object.
- See Also:
- DataSource
 
 - 
getFilepublic java.io.File getFile() Return the File object that corresponds to this FileDataSource.- Returns:
- the File object for the file represented by this object.
 
 - 
setFileTypeMappublic void setFileTypeMap(FileTypeMap map) Set the FileTypeMap to use with this FileDataSource- Parameters:
- map- The FileTypeMap for this object.
 
 
- 
 
-