Class PathDataSource

java.lang.Object
org.apache.commons.mail2.jakarta.activation.PathDataSource
All Implemented Interfaces:
jakarta.activation.DataSource

public final class PathDataSource extends Object implements 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 Details

    • PathDataSource

      public PathDataSource(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(Path path, jakarta.activation.FileTypeMap typeMap, 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 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 the FileTypeMap.getDefaultFileTypeMap() method to acquire a default FileTypeMap.

      By default, the FileTypeMap used will be a MimetypesFileTypeMap.

      Specified by:
      getContentType in interface jakarta.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 interface jakarta.activation.DataSource
      Returns:
      an InputStream
      Throws:
      IOException
    • getName

      public String getName()
      Gets the name of this object. The FileDataSource will return the file name of the object.
      Specified by:
      getName in interface jakarta.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 interface jakarta.activation.DataSource
      Returns:
      an OutputStream
      Throws:
      IOException
    • getPath

      public Path getPath()
      Gets the File object that corresponds to this PathDataSource.
      Returns:
      the File object for the file represented by this object.