Class PathDataSource

  • All Implemented Interfaces:
    javax.activation.DataSource

    public final class PathDataSource
    extends java.lang.Object
    implements javax.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

      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.String getContentType()
      Gets the MIME type of the data as a String.
      java.io.InputStream getInputStream()
      Gets an InputStream representing the the data and will throw an IOException if it can not do so.
      java.lang.String getName()
      Gets the name of this object.
      java.io.OutputStream getOutputStream()
      Gets an OutputStream representing the the data and will throw an IOException if it can not do so.
      java.nio.file.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 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 the FileTypeMap.getDefaultFileTypeMap() method to acquire a default FileTypeMap.

        By default, the FileTypeMap used will be a MimetypesFileTypeMap.

        Specified by:
        getContentType in interface javax.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:
        getInputStream in interface javax.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:
        getName in interface javax.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:
        getOutputStream in interface javax.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.