Top Description Fields Constructors Methods
jakarta.activation

public Class FileDataSource

extends Object
implements DataSource
Class Inheritance
All Implemented Interfaces
jakarta.activation.DataSource
Imports
java.io.InputStream, .OutputStream, .File, .FileInputStream, .FileOutputStream, .IOException

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
jakarta.activation.DataSource, jakarta.activation.FileTypeMap, jakarta.activation.MimetypesFileTypeMap

Field Summary

Modifier and TypeField and Description
private File
private FileTypeMap

Constructor Summary

AccessConstructor and Description
public
FileDataSource(File
the file
file
)

Creates a FileDataSource from a File object.

public
FileDataSource(String
the system-dependent file name.
name
)

Creates a FileDataSource from the specified path name.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the MIME Type
getContentType
()

Implements jakarta.activation.DataSource.getContentType.

This method returns the MIME type of the data in the form of a string.
public File

Returns:

the File object for the file represented by this object.
getFile
()

Return the File object that corresponds to this FileDataSource.

public InputStream

Returns:

an InputStream
getInputStream
()

Implements jakarta.activation.DataSource.getInputStream.

This method will return an InputStream representing the the data and will throw an IOException if it can not do so.
public String

Returns:

the name of the object.
getName
()

Implements jakarta.activation.DataSource.getName.

Return the name of this object.
public OutputStream

Returns:

an OutputStream
getOutputStream
()

Implements jakarta.activation.DataSource.getOutputStream.

This method will return an OutputStream representing the the data and will throw an IOException if it can not do so.
public void
setFileTypeMap(FileTypeMap
The FileTypeMap for this object.
map
)

Set the FileTypeMap to use with this FileDataSource

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_fileback to summary
private File _file
typeMapback to summary
private FileTypeMap typeMap

Constructor Detail

FileDataSourceback to summary
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:File

the file

FileDataSourceback to summary
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:String

the system-dependent file name.

Method Detail

getContentTypeback to summary
public String getContentType()

Implements jakarta.activation.DataSource.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:String

the MIME Type

See Also
jakarta.activation.FileTypeMap#getDefaultFileTypeMap
getFileback to summary
public File getFile()

Return the File object that corresponds to this FileDataSource.

Returns:File

the File object for the file represented by this object.

getInputStreamback to summary
public InputStream getInputStream() throws IOException

Implements jakarta.activation.DataSource.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:InputStream

an InputStream

Exceptions
IOException:

Doc from jakarta.activation.DataSource.getInputStream.

for failures creating the InputStream

getNameback to summary
public String getName()

Implements jakarta.activation.DataSource.getName.

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

Returns:String

the name of the object.

See Also
jakarta.activation.DataSource
getOutputStreamback to summary
public OutputStream getOutputStream() throws IOException

Implements jakarta.activation.DataSource.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:OutputStream

an OutputStream

Exceptions
IOException:

Doc from jakarta.activation.DataSource.getOutputStream.

for failures creating the OutputStream

setFileTypeMapback to summary
public void setFileTypeMap(FileTypeMap map)

Set the FileTypeMap to use with this FileDataSource

Parameters
map:FileTypeMap

The FileTypeMap for this object.