- java.lang.Object
-
- javax.activation.FileDataSource
-
- All Implemented Interfaces:
- DataSource
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.- Since:
- 1.6
- See Also:
DataSource
,FileTypeMap
,MimetypesFileTypeMap
-
-
Constructor Summary
Constructors Constructor and Description FileDataSource(File file)
Creates a FileDataSource from a File object.FileDataSource(String name)
Creates a FileDataSource from the specified path name.
-
Method Summary
Methods Modifier and Type Method and Description 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
-
-
-
Constructor Detail
-
FileDataSource
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
-
FileDataSource
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.
-
-
Method Detail
-
getInputStream
public InputStream getInputStream() throws IOException
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.- Specified by:
getInputStream
in interfaceDataSource
- Returns:
- an InputStream
- Throws:
IOException
-
getOutputStream
public OutputStream getOutputStream() throws IOException
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.- Specified by:
getOutputStream
in interfaceDataSource
- Returns:
- an OutputStream
- Throws:
IOException
-
getContentType
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 thegetDefaultFileTypeMap
method on FileTypeMap to acquire a default FileTypeMap. Note: By default, the FileTypeMap used will be a MimetypesFileTypeMap.- Specified by:
getContentType
in interfaceDataSource
- Returns:
- the MIME Type
- See Also:
FileTypeMap.getDefaultFileTypeMap()
-
getName
public String getName()
Return the name of this object. The FileDataSource will return the file name of the object.- Specified by:
getName
in interfaceDataSource
- Returns:
- the name of the object.
- See Also:
DataSource
-
getFile
public File getFile()
Return the File object that corresponds to this FileDataSource.- Returns:
- the File object for the file represented by this object.
-
setFileTypeMap
public void setFileTypeMap(FileTypeMap map)
Set the FileTypeMap to use with this FileDataSource- Parameters:
map
- The FileTypeMap for this object.
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/11/2024 22:12:23 Cette version de la page est en cache (à la date du 21/11/2024 22:12:23) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 11/06/2005, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/activation/FileDataSource.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.