public class ExtractorDataSource extends ModifiableParametricBase implements java.io.Closeable
Extractor
s.
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
InputStream
- use getInputStream()
method,BufferedReader
- use getBufferedReader()
method,byte[]
- use getBinaryData()
method, orOutputStream
- use pipe(java.io.OutputStream)
method.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.
Modifier and Type | Class and Description |
---|---|
static class |
ExtractorDataSource.PipeThread
Helper class that pipes the given data source to a given output stream in thread.
|
Constructor and Description |
---|
ExtractorDataSource(byte[] inputData)
Create new instance of ExtractorDataSource using data from the given array of bytes.
|
ExtractorDataSource(byte[] inputData,
java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
Create new instance of ExtractorDataSource using data from the given array of bytes.
|
ExtractorDataSource(byte[] inputData,
java.lang.String locator,
java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
Create new instance of ExtractorDataSource using data from the given array of bytes.
|
ExtractorDataSource(ExtractorDataSource dataSource)
Create new instance of ExtractorDataSource as a copy of another ExtractorDataSource.
|
ExtractorDataSource(java.io.File file)
Create new instance of ExtractorDataSource using data from
File . |
ExtractorDataSource(java.io.File file,
java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
Create new instance of ExtractorDataSource using data from
File . |
ExtractorDataSource(java.io.InputStream inputStream)
Create new instance of ExtractorDataSource using data from
InputStream . |
ExtractorDataSource(java.io.InputStream inputStream,
java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
Create new instance of ExtractorDataSource using data from
InputStream . |
ExtractorDataSource(java.io.InputStream inputStream,
java.lang.String locator,
java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
Create new instance of ExtractorDataSource using data from
InputStream . |
ExtractorDataSource(java.lang.Object dataSource,
java.lang.String locator,
java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
Create new instance of ExtractorDataSource for a given data source object.
|
ExtractorDataSource(java.net.URL url,
java.lang.String mimeTypeRegexp)
Create new instance of ExtractorDataSource using data downloaded from
URL . |
ExtractorDataSource(java.net.URL url,
java.lang.String mimeTypeRegexp,
java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
Create new instance of ExtractorDataSource using data downloaded from
URL . |
Modifier and Type | Method and Description |
---|---|
static ExtractorDataSource |
addContentParameter(ExtractorDataSource dataSource,
java.lang.String contentParameterName)
Returns a data source that has a parameter containing the binary content of the original data source.
|
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 |
getLocator()
Returns the locator of the data source.
|
void |
pipe(java.io.OutputStream outputStream)
Output all data from this data source to the given
outputStream . |
void |
pipeToFile(java.io.File file)
Output all data from this data source to the given
file . |
java.io.File |
pipeToTemporaryFile(java.lang.String prefix,
java.lang.String suffix,
java.io.File directory)
Output all data from this data source to a automatically generated temporary file.
|
void |
reset()
Reset this data source, i.e. the data will be provided from beginning.
|
java.lang.String |
toString() |
removeParameter, setParameter
append, appendParameter, clearSurplusData, clearSurplusData, containsParameter, getParameter, getParameter, getParameter, getParameterCount, getParameterMap, getParameterNames, getRequiredParameter, getRequiredParameter, toStringWithCast
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
containsParameter, getParameter, getParameter, getParameter, getParameterCount, getParameterMap, getParameterNames, getRequiredParameter, getRequiredParameter
public ExtractorDataSource(java.io.InputStream inputStream, java.lang.String locator, java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
InputStream
.inputStream
- the input stream from which to download the datalocator
- locator of the input stream dataadditionalParameters
- the additional parameters for this data sourcepublic ExtractorDataSource(java.io.InputStream inputStream, java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
InputStream
.inputStream
- the input stream from which to download the dataadditionalParameters
- the additional parameters for this data sourcepublic ExtractorDataSource(java.io.InputStream inputStream)
InputStream
.inputStream
- the input stream from which to download the datapublic ExtractorDataSource(byte[] inputData, java.lang.String locator, java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
inputData
- the array of bytes that represents the datalocator
- locator of the byte input dataadditionalParameters
- the additional parameters for this data sourcepublic ExtractorDataSource(byte[] inputData, java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters)
inputData
- the array of bytes that represents the dataadditionalParameters
- the additional parameters for this data sourcepublic ExtractorDataSource(byte[] inputData)
inputData
- the array of bytes that represents the datapublic ExtractorDataSource(java.net.URL url, java.lang.String mimeTypeRegexp, java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters) throws java.io.IOException
URL
.url
- the URL from which to download the datamimeTypeRegexp
- regular expression for the mimetype of the data on the given url
additionalParameters
- the additional parameters for this data sourcejava.io.IOException
- if there was an error reading the datapublic ExtractorDataSource(java.net.URL url, java.lang.String mimeTypeRegexp) throws java.io.IOException
URL
.url
- the URL from which to download the datamimeTypeRegexp
- regular expression for the mimetype of the data on the given url
java.io.IOException
- if there was an error reading the datapublic ExtractorDataSource(java.io.File file, java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters) throws java.io.IOException
File
.file
- the file from which to download the dataadditionalParameters
- the additional parameters for this data sourcejava.io.IOException
- if there was an error opening the filepublic ExtractorDataSource(java.io.File file) throws java.io.IOException
File
.file
- the file from which to download the datajava.io.IOException
- if there was an error opening the filepublic ExtractorDataSource(ExtractorDataSource dataSource) throws java.io.IOException
dataSource
- the data source to copy fromjava.io.IOException
- if there was an error opening the data sourcepublic ExtractorDataSource(java.lang.Object dataSource, java.lang.String locator, java.util.Map<java.lang.String,? extends java.lang.Object> additionalParameters) throws java.io.IOException
byte[]
array, an InputStream
,
a File
, or URL
. In case the data source is a String
,
it is first converted to URL
and if it fails, File
is used.dataSource
- the data source objectlocator
- locator of the data sourceadditionalParameters
- the additional parameters for this data sourcejava.io.IOException
- if there was an error opening the data sourcepublic static ExtractorDataSource addContentParameter(ExtractorDataSource dataSource, java.lang.String contentParameterName) throws java.io.IOException
contentParameterName
is null or the
given data source already contains the parameter of that name, the original
data source is returned.dataSource
- the data source the binary content of which to getcontentParameterName
- the name of the parameter that holds the binary contentjava.io.IOException
- if there was a problem reading the binary datapublic java.lang.Object getDataSource()
File
, InputStream
or URL
).public java.lang.String getLocator()
public java.io.InputStream getInputStream()
Note that the data source is not closed - use InputStream.close()
method instead.
public java.io.BufferedReader getBufferedReader()
Note that the data source is not closed - use BufferedReader.close()
method instead.
public byte[] getBinaryData() throws java.io.IOException
Note that the data source is closed after this method is used.
java.io.IOException
- if there was a problem reading from the data sourcepublic void pipe(java.io.OutputStream outputStream) throws java.io.IOException
outputStream
.
Note that the data source is closed after this method is used.
outputStream
- the stream to which to write the datajava.io.IOException
- if there was an error reading from this data source or writing to the output streampublic void pipeToFile(java.io.File file) throws java.io.IOException
file
.
Note that the given file is overwritten if exists and this data source is closed after this method is used.
file
- the file to which to write the datajava.io.IOException
- if there was an error reading from this data source or writing to the output streampublic java.io.File pipeToTemporaryFile(java.lang.String prefix, java.lang.String suffix, java.io.File directory) throws java.io.IOException
File.createTempFile(java.lang.String, java.lang.String, java.io.File)
.
Note that this data source is closed after this method is used.
prefix
- the prefix string to be used in generating the file's namesuffix
- the suffix string to be used in generating the file's namedirectory
- the directory in which the file is to be created, or
null
if the default temporary-file directory is to be usedjava.io.IOException
- if there was an error reading from this data source or writing to the output streampublic void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public void reset() throws java.io.IOException
java.io.IOException
- if there was an I/O error re-opening the data sourcepublic java.lang.String toString()
toString
in class ParametricBase