org.semanticdesktop.aperture.accessor
Interface FileDataObject

All Superinterfaces:
DataObject
All Known Implementing Classes:
FileDataObjectBase

public interface FileDataObject
extends DataObject

A general interface for DataObjects that have File-like semantics. Examples are files or web pages.


Method Summary
 File downloadContent()
          Downloads the entire content of the stream to a temporary file (created with File.createTempFile(String, String)).
 InputStream getContent()
          Gets an InputStream containing the content represented by the DataObject.
 File getFile()
          Returns an instance of java.io.File representing the content of this FileDataObject.
 void setContent(InputStream stream)
          Sets the InputStream containing the content represented by the DataObject.
 void setFile(File file)
          Sets the file containing the content represented by this FileDataObject.
 
Methods inherited from interface org.semanticdesktop.aperture.accessor.DataObject
dispose, getDataSource, getID, getMetadata
 

Method Detail

getContent

InputStream getContent()
                       throws IOException
Gets an InputStream containing the content represented by the DataObject.

The returned InputStream is required to support marking (markSupported() must return true). Calling this method multiple times may return references to one-and-the-same InputStream instance. Care should therefore be taken to mark and reset the stream when the stream's content is to be read again later.

The returned InputStream is null in cases where the physical resource could not be accessed, e.g. in case of missing file read permissions.

Returns:
An InputStream from which the content of the data object can be read, or null when the stream cannot be accessed.
Throws:
IOException - If an I/O error occurred.

setContent

void setContent(InputStream stream)
Sets the InputStream containing the content represented by the DataObject. The specified InputStream is required to support marking (markSupported() must return true).

Parameters:
stream - The InputStream containing the resource's content.

getFile

File getFile()
Returns an instance of java.io.File representing the content of this FileDataObject. If no such file instance is available null is returned.

If you need a File instance (e.g. to pass it to a FileExtractor) and this method returns null, you can use the downloadContent() method. If the downloadContent() method doesn't meet your needs, you can use the stream returned by getContent() and implement the download process by yourself. Note that the IOUtil.writeStream(InputStream, File) method may be useful for this.

Returns:
a File representing the content of this FileDataObject or null if no such File is available

downloadContent

File downloadContent()
                     throws IOException
Downloads the entire content of the stream to a temporary file (created with File.createTempFile(String, String)). It is the responsibility of the user to delete the file if it is no longer needed.

This method works only if the content stream hasn't been used or if it has been reset prior to calling this method. Otherwise the downloaded file would be corrupted. Aperture tries to check for this kind of error, but nevertheless this method should be used with care.

Note that the content stream may become unusable after a call to this method.

This method will always create a temporary file, including cases when the getFile() method returns a non-null value.

Returns:
the File instance for the temporary file where the content of the stream has been downloaded.
Throws:
IOException - If the content stream is not at the beginning of the file, or if an I/O error occured during the download process.

setFile

void setFile(File file)
Sets the file containing the content represented by this FileDataObject.

Parameters:
file - the file with the content of this FileDataObject


Copyright © 2010 Aperture Development Team. All Rights Reserved.