com.openexchange.mail.mime.datasource
Class FileDataSource

java.lang.Object
  extended by com.openexchange.mail.mime.datasource.FileDataSource
All Implemented Interfaces:
javax.activation.DataSource

public final class FileDataSource
extends java.lang.Object
implements javax.activation.DataSource

FileDataSource - A simple data source that encapsulates a file.

Author:
Thorben Betten

Constructor Summary
FileDataSource(java.io.File file)
          Creates a FileDataSource from a File object.
FileDataSource(java.io.File file, java.lang.String contentType)
          Creates a FileDataSource from a File object.
FileDataSource(java.lang.String name)
          Creates a FileDataSource from the specified path name.
FileDataSource(java.lang.String name, java.lang.String contentType)
          Creates a FileDataSource from the specified path name.
 
Method Summary
 java.lang.String getContentType()
           
 java.io.File getFile()
          Return the file that corresponds to this FileDataSource.
 java.io.InputStream getInputStream()
           
 java.lang.String getName()
           
 java.io.OutputStream getOutputStream()
           
 void setContentType(java.lang.String contentType)
          Sets the content type.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileDataSource

public FileDataSource(java.io.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.

Content type is initially set to "application/octet-stream".

Parameters:
file - The file

FileDataSource

public FileDataSource(java.io.File file,
                      java.lang.String contentType)
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
contentType - The content type

FileDataSource

public FileDataSource(java.lang.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.

Content type is initially set to "application/octet-stream".

Parameters:
name - The system-dependent file name.

FileDataSource

public FileDataSource(java.lang.String name,
                      java.lang.String contentType)
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.

Content type is initially set to "application/octet-stream".

Parameters:
name - The system-dependent file name.
contentType - The content type
Method Detail

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Specified by:
getInputStream in interface javax.activation.DataSource
Throws:
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Specified by:
getOutputStream in interface javax.activation.DataSource
Throws:
java.io.IOException

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in interface javax.activation.DataSource

getName

public java.lang.String getName()
Specified by:
getName in interface javax.activation.DataSource

getFile

public java.io.File getFile()
Return the file that corresponds to this FileDataSource.

Returns:
The file.

setContentType

public void setContentType(java.lang.String contentType)
Sets the content type.

Parameters:
contentType - The content type.