FileDocCategorySizeDatePackage
FileDataSource.javaAPI DocGlassfish v2 API6151Mon May 14 15:29:52 BST 2007javax.activation

FileDataSource

public class FileDataSource extends Object implements DataSource
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
javax.activation.DataSource
see
javax.activation.FileTypeMap
see
javax.activation.MimetypesFileTypeMap

Fields Summary
private File
_file
private FileTypeMap
typeMap
Constructors 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.

param
file the file


                                        
       
	_file = file;	// save the file Object...
    
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.

param
name the system-dependent file name.

	this(new File(name));	// use the file constructor
    
Methods Summary
public java.lang.StringgetContentType()
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.

return
the MIME Type
see
javax.activation.FileTypeMap#getDefaultFileTypeMap

	// check to see if the type map is null?
	if (typeMap == null)
	    return FileTypeMap.getDefaultFileTypeMap().getContentType(_file);
	else
	    return typeMap.getContentType(_file);
    
public java.io.FilegetFile()
Return the File object that corresponds to this FileDataSource.

return
the File object for the file represented by this object.

	return _file;
    
public java.io.InputStreamgetInputStream()
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.

return
an InputStream

	return new FileInputStream(_file);
    
public java.lang.StringgetName()
Return the name of this object. The FileDataSource will return the file name of the object.

return
the name of the object.
see
javax.activation.DataSource

	return _file.getName();
    
public java.io.OutputStreamgetOutputStream()
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.

return
an OutputStream

	return new FileOutputStream(_file);
    
public voidsetFileTypeMap(javax.activation.FileTypeMap map)
Set the FileTypeMap to use with this FileDataSource

param
map The FileTypeMap for this object.

	typeMap = map;