messif.objects.extraction
Class ExtractorDataSource

java.lang.Object
  extended by messif.objects.extraction.ExtractorDataSource
All Implemented Interfaces:
java.io.Closeable

public class ExtractorDataSource
extends java.lang.Object
implements java.io.Closeable

Provides a data source for Extractors. It can be constructed either from a InputStream, File or a URL. Depending on that, the source's name is set to either null, the name of the file, or the URL. The data can be used by the extractors as either

Note that the data can be used only as one of the aforementioned types and, once read, they are no longer available from the source.


Constructor Summary
ExtractorDataSource(java.io.File file)
          Create new instance of ExtractorDataSource using data from File.
ExtractorDataSource(java.io.InputStream inputStream, java.lang.String name)
          Create new instance of ExtractorDataSource using data from InputStream.
ExtractorDataSource(java.net.URL url, java.lang.String mimeTypeRegexp)
          Create new instance of ExtractorDataSource using data downloaded from URL.
 
Method Summary
 void close()
           
 byte[] getBinaryData()
          Return this data source as a byte buffer.
 java.io.BufferedReader getBufferedReader()
          Return this data source as buffered reader.
 java.lang.Object getDataSource()
          Returns the remembered data source (can be File, InputStream or URL).
 java.io.InputStream getInputStream()
          Return this data source as input stream.
 java.lang.String getName()
          Returns the name of this data source.
 void pipe(java.io.OutputStream outputStream)
          Output all data from this data source to the given outputStream.
 void reset()
          Reset this data source, i.e. the data will be provided from beginning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtractorDataSource

public ExtractorDataSource(java.io.InputStream inputStream,
                           java.lang.String name)
Create new instance of ExtractorDataSource using data from InputStream.

Parameters:
inputStream - the input stream from which to download the data
name - the name of this data source

ExtractorDataSource

public ExtractorDataSource(java.net.URL url,
                           java.lang.String mimeTypeRegexp)
                    throws java.io.IOException
Create new instance of ExtractorDataSource using data downloaded from URL.

Parameters:
url - the URL from which to download the data
mimeTypeRegexp - regular expression for the mimetype of the data on the given url
Throws:
java.io.IOException - if there was an error reading the data

ExtractorDataSource

public ExtractorDataSource(java.io.File file)
                    throws java.io.IOException
Create new instance of ExtractorDataSource using data from File.

Parameters:
file - the file from which to download the data
Throws:
java.io.IOException - if there was an error opening the file
Method Detail

getName

public java.lang.String getName()
Returns the name of this data source.

Returns:
the name of this data source

getDataSource

public java.lang.Object getDataSource()
Returns the remembered data source (can be File, InputStream or URL).

Returns:
the remembered data source

getInputStream

public java.io.InputStream getInputStream()
Return this data source as input stream.

Note that the data source is not closed - use InputStream.close() method instead.

Returns:
this data source as input stream

getBufferedReader

public java.io.BufferedReader getBufferedReader()
Return this data source as buffered reader.

Note that the data source is not closed - use BufferedReader.close() method instead.

Returns:
a buffer containing the data

getBinaryData

public byte[] getBinaryData()
                     throws java.io.IOException
Return this data source as a byte buffer.

Note that the data source is closed after this method is used.

Returns:
a buffer containing the data
Throws:
java.io.IOException - if there was a problem reading from the data source

pipe

public void pipe(java.io.OutputStream outputStream)
          throws java.io.IOException
Output all data from this data source to the given outputStream.

Note that the data source is closed after this method is used.

Parameters:
outputStream - the stream to which to write the data
Throws:
java.io.IOException - if there was an error reading from this data source or writing to the output stream

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException

reset

public void reset()
           throws java.io.IOException
Reset this data source, i.e. the data will be provided from beginning. Note that reset is available only if a resetable data source was used in constructor (e.g. file or url).

Throws:
java.io.IOException - if there was an I/O error re-opening the data source