Class PathDataSource
java.lang.Object
org.apache.commons.mail2.jakarta.activation.PathDataSource
- All Implemented Interfaces:
jakarta.activation.DataSource
A JavaBeans Activation Framework
DataSource
that encapsulates a Path
. It provides data typing services via a FileTypeMap
object.- Since:
- 1.6.0
- See Also:
-
DataSource
FileTypeMap
MimetypesFileTypeMap
-
Constructor Summary
ConstructorDescriptionPathDataSource
(Path path) Creates a new instance from a Path.PathDataSource
(Path path, jakarta.activation.FileTypeMap typeMap, OpenOption... options) Creates a new instance from a Path. -
Method Summary
Modifier and TypeMethodDescriptionGets the MIME type of the data as a String.Gets an InputStream representing the the data and will throw an IOException if it can not do so.getName()
Gets the name of this object.Gets an OutputStream representing the the data and will throw an IOException if it can not do so.getPath()
Gets the File object that corresponds to this PathDataSource.
-
Constructor Details
-
PathDataSource
Creates a new instance from a Path.The file will not actually be opened until a method is called that requires the path to be opened.
The type map defaults to
FileTypeMap.getDefaultFileTypeMap()
.- Parameters:
path
- the path
-
PathDataSource
Creates a new instance from a Path.The file will not actually be opened until a method is called that requires the path to be opened.
- Parameters:
path
- the path, non-null.typeMap
- the type map, non-null.options
- options for opening file streams.
-
-
Method Details
-
getContentType
Gets the MIME type of the data as a String. This method uses the currently installed FileTypeMap. If there is no FileTypeMap explicitly set, the FileDataSource will call theFileTypeMap.getDefaultFileTypeMap()
method to acquire a default FileTypeMap.By default, the
FileTypeMap
used will be aMimetypesFileTypeMap
.- Specified by:
getContentType
in interfacejakarta.activation.DataSource
- Returns:
- the MIME Type
- See Also:
-
FileTypeMap.getDefaultFileTypeMap()
-
getInputStream
Gets 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:
getInputStream
in interfacejakarta.activation.DataSource
- Returns:
- an InputStream
- Throws:
IOException
-
getName
Gets the name of this object. The FileDataSource will return the file name of the object.- Specified by:
getName
in interfacejakarta.activation.DataSource
- Returns:
- the name of the object or null.
- See Also:
-
DataSource
-
getOutputStream
Gets 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:
getOutputStream
in interfacejakarta.activation.DataSource
- Returns:
- an OutputStream
- Throws:
IOException
-
getPath
Gets the File object that corresponds to this PathDataSource.- Returns:
- the File object for the file represented by this object.
-