public class

FileDataSource

extends Object
implements DataSource
java.lang.Object
   ↳ com.google.code.javax.activation.FileDataSource

Class Overview

The FileDataSource class implements a simple DataSource object that encapsulates a file. It provides data typing services via a FileTypeMap object.

FileDataSource Typing Semantics

The FileDataSource class delegates data typing of files to an object subclassed from the FileTypeMap class. The setFileTypeMap method can be used to explicitly set the FileTypeMap for an instance of FileDataSource. If no FileTypeMap is set, the FileDataSource will call the FileTypeMap's getDefaultFileTypeMap method to get the System's default FileTypeMap.

See Also
  • javax.activation.DataSource
  • javax.activation.FileTypeMap
  • javax.activation.MimetypesFileTypeMap

Summary

Fields
private File _file
private FileTypeMap typeMap
Public Constructors
FileDataSource(File file)
Creates a FileDataSource from a File object.
FileDataSource(String name)
Creates a FileDataSource from the specified path name.
Public Methods
String getContentType()
This method returns the MIME type of the data in the form of a string.
File getFile()
Return the File object that corresponds to this FileDataSource.
InputStream getInputStream()
This method will return an InputStream representing the the data and will throw an IOException if it can not do so.
String getName()
Return the name of this object.
OutputStream getOutputStream()
This method will return an OutputStream representing the the data and will throw an IOException if it can not do so.
void setFileTypeMap(FileTypeMap map)
Set the FileTypeMap to use with this FileDataSource
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.code.javax.activation.DataSource

Fields

private File _file

private FileTypeMap typeMap

Public Constructors

public FileDataSource (File file)

Creates a FileDataSource from a File object. Note: The file will not actually be opened until a method is called that requires the file to be opened.

Parameters
file The file

public FileDataSource (String name)

Creates a FileDataSource from the specified path name. Note: The file will not actually be opened until a method is called that requires the file to be opened.

Parameters
name The system-dependent file name.

Public Methods

public String getContentType ()

This method returns the MIME type of the data in the form of a string. This method uses the currently installed FileTypeMap. If there is no FileTypeMap explictly set, the FileDataSource will call the getDefaultFileTypeMap method on FileTypeMap to acquire a default FileTypeMap. Note: By default, the FileTypeMap used will be a MimetypesFileTypeMap.

Returns
  • the MIME Type

public File getFile ()

Return the File object that corresponds to this FileDataSource.

Returns
  • the File object for the file represented by this object.

public InputStream getInputStream ()

This method will return 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.

Returns
  • an InputStream
Throws
IOException

public String getName ()

Return the name of this object. The FileDataSource will return the file name of the object.

Returns
  • the name of the object.
See Also
  • javax.activation.DataSource

public OutputStream getOutputStream ()

This method will return 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.

Returns
  • an OutputStream
Throws
IOException

public void setFileTypeMap (FileTypeMap map)

Set the FileTypeMap to use with this FileDataSource

Parameters
map The FileTypeMap for this object.