Class PathDataSource
- java.lang.Object
-
- org.apache.commons.mail.activation.PathDataSource
-
- All Implemented Interfaces:
javax.activation.DataSource
public final class PathDataSource extends java.lang.Object implements javax.activation.DataSource
A JavaBeans Activation FrameworkDataSourcethat encapsulates aPath. It provides data typing services via aFileTypeMapobject.- Since:
- 1.6.0
- See Also:
DataSource,FileTypeMap,MimetypesFileTypeMap
-
-
Constructor Summary
Constructors Constructor Description PathDataSource(java.nio.file.Path path)Creates a new instance from a Path.PathDataSource(java.nio.file.Path path, javax.activation.FileTypeMap typeMap, java.nio.file.OpenOption... options)Creates a new instance from a Path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetContentType()Gets the MIME type of the data as a String.java.io.InputStreamgetInputStream()Gets an InputStream representing the the data and will throw an IOException if it can not do so.java.lang.StringgetName()Gets the name of this object.java.io.OutputStreamgetOutputStream()Gets an OutputStream representing the the data and will throw an IOException if it can not do so.java.nio.file.PathgetPath()Gets the File object that corresponds to this PathDataSource.
-
-
-
Constructor Detail
-
PathDataSource
public PathDataSource(java.nio.file.Path path)
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
public PathDataSource(java.nio.file.Path path, javax.activation.FileTypeMap typeMap, java.nio.file.OpenOption... options)
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 Detail
-
getContentType
public java.lang.String 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
FileTypeMapused will be aMimetypesFileTypeMap.- Specified by:
getContentTypein interfacejavax.activation.DataSource- Returns:
- the MIME Type
- See Also:
FileTypeMap.getDefaultFileTypeMap()
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
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:
getInputStreamin interfacejavax.activation.DataSource- Returns:
- an InputStream
- Throws:
java.io.IOException
-
getName
public java.lang.String getName()
Gets the name of this object. The FileDataSource will return the file name of the object.- Specified by:
getNamein interfacejavax.activation.DataSource- Returns:
- the name of the object or null.
- See Also:
DataSource
-
getOutputStream
public java.io.OutputStream getOutputStream() throws java.io.IOException
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:
getOutputStreamin interfacejavax.activation.DataSource- Returns:
- an OutputStream
- Throws:
java.io.IOException
-
getPath
public java.nio.file.Path getPath()
Gets the File object that corresponds to this PathDataSource.- Returns:
- the File object for the file represented by this object.
-
-