Package org.apache.commons.mail.activation

# Class PathDataSource

java.lang.Object
org.apache.commons.mail.activation.PathDataSource

All Implemented Interfaces:
  `DataSource`

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

  Constructors
  Constructor
  Description
  `PathDataSource(Path path)`
  Creates a new instance from a Path.
  `PathDataSource(Path path, FileTypeMap typeMap, OpenOption... options)`
  Creates a new instance from a Path.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `getContentType()`
  Gets the MIME type of the data as a String.
  `InputStream`
  `getInputStream()`
  Gets an InputStream representing the the data and will throw an IOException if it can not do so.
  `String`
  `getName()`
  Gets the name of this object.
  `OutputStream`
  `getOutputStream()`
  Gets an OutputStream representing the the data and will throw an IOException if it can not do so.
  `Path`
  `getPath()`
  Gets the File object that corresponds to this PathDataSource.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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, 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

    public 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 the `FileTypeMap.getDefaultFileTypeMap()` method to acquire a default FileTypeMap.

    By default, the `FileTypeMap` used will be a `MimetypesFileTypeMap`.

    Specified by:
      `getContentType` in interface `DataSource`
    Returns:
      the MIME Type
    See Also:
      - `FileTypeMap.getDefaultFileTypeMap()`

  - ### getInputStream

    public InputStream getInputStream() throws 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:
      `getInputStream` in interface `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 `DataSource`
    Returns:
      the name of the object or null.
    See Also:
      - `DataSource`

  - ### getOutputStream

    public OutputStream getOutputStream() throws 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:
      `getOutputStream` in interface `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.