org.semanticdesktop.aperture.accessor.base
Class FileDataObjectBase

java.lang.Object
  extended by org.semanticdesktop.aperture.accessor.base.DataObjectBase
      extended by org.semanticdesktop.aperture.accessor.base.FileDataObjectBase
All Implemented Interfaces:
DataObject, FileDataObject

public class FileDataObjectBase
extends DataObjectBase
implements FileDataObject

A trivial default implementation of FileDataObject.


Constructor Summary
FileDataObjectBase()
          Default constructor.
FileDataObjectBase(URI id, DataSource dataSource, RDFContainer metadata, File file)
          Constructor accepting a file.
FileDataObjectBase(URI id, DataSource dataSource, RDFContainer metadata, InputStream content)
          Constructor accepting a content stream.
 
Method Summary
protected  void closeContent()
          Closes the content stream and sets it to null.
 void dispose()
          Closes the stream encapsulated by this FileDataObject.
 File downloadContent()
          Downloads the entire content of the stream to a temporary file (created with File.createTempFile(String, String)).
 void finalize()
           
 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 content)
          Sets the InputStream containing the content represented by the DataObject.
 void setFile(File file)
          Sets the file containing the content represented by this FileDataObject.
protected  void setFileWithoutChecks(File file)
          Sets the file without checking if it exists and is readable, and without updating the content.
 
Methods inherited from class org.semanticdesktop.aperture.accessor.base.DataObjectBase
getDataSource, getID, getMetadata, getWrappedDataObject, isDisposed, setDataSource, setID, setMetadata, setWrappedDataObject
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.semanticdesktop.aperture.accessor.DataObject
getDataSource, getID, getMetadata
 

Constructor Detail

FileDataObjectBase

public FileDataObjectBase()
Default constructor.


FileDataObjectBase

public FileDataObjectBase(URI id,
                          DataSource dataSource,
                          RDFContainer metadata,
                          InputStream content)
Constructor accepting a content stream.

Parameters:
id - URI of this data object (obligatory)
dataSource - the data source where this data object came from (optional)
metadata - the metadata of this data object (obligatory)
content - the content stream (must support mark()).

FileDataObjectBase

public FileDataObjectBase(URI id,
                          DataSource dataSource,
                          RDFContainer metadata,
                          File file)
Constructor accepting a file.

Parameters:
id - URI of this data object (obligatory)
dataSource - the data source where this data object came from (optional)
metadata - the metadata of this data object (obligatory)
file - the java.io.File instance with the content of this data object. The file must be non-null, must exist and be readable, otherwise exceptions will be thrown
Method Detail

finalize

public void finalize()
              throws Throwable
Overrides:
finalize in class DataObjectBase
Throws:
Throwable

setContent

public void setContent(InputStream content)
Description copied from interface: FileDataObject
Sets the InputStream containing the content represented by the DataObject. The specified InputStream is required to support marking (markSupported() must return true).

Specified by:
setContent in interface FileDataObject
Parameters:
content - The InputStream containing the resource's content.

getContent

public InputStream getContent()
Description copied from interface: FileDataObject
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.

Specified by:
getContent in interface FileDataObject
Returns:
An InputStream from which the content of the data object can be read, or null when the stream cannot be accessed.

setFile

public void setFile(File file)
Description copied from interface: FileDataObject
Sets the file containing the content represented by this FileDataObject.

Specified by:
setFile in interface FileDataObject
Parameters:
file - the file with the content of this FileDataObject

getFile

public File getFile()
Description copied from interface: FileDataObject
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 FileDataObject.downloadContent() method. If the FileDataObject.downloadContent() method doesn't meet your needs, you can use the stream returned by FileDataObject.getContent() and implement the download process by yourself. Note that the IOUtil.writeStream(InputStream, File) method may be useful for this.

Specified by:
getFile in interface FileDataObject
Returns:
a File representing the content of this FileDataObject or null if no such File is available

setFileWithoutChecks

protected void setFileWithoutChecks(File file)
Sets the file without checking if it exists and is readable, and without updating the content. Subclasses should excercise caution when using this method.

Parameters:
file - the file to set

downloadContent

public File downloadContent()
                     throws IOException
Description copied from interface: FileDataObject
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 FileDataObject.getFile() method returns a non-null value.

Specified by:
downloadContent in interface FileDataObject
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.

dispose

public void dispose()
Closes the stream encapsulated by this FileDataObject. If this object contains a wrapped data object (set with the DataObjectBase.setWrappedDataObject(DataObject)) method - the wrapped data object is also disposed.

Specified by:
dispose in interface DataObject
Overrides:
dispose in class DataObjectBase

closeContent

protected void closeContent()
Closes the content stream and sets it to null.



Copyright © 2010 Aperture Development Team. All Rights Reserved.