|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmessif.objects.extraction.Extractors
public abstract class Extractors
Collection of utility methods for Extractor
s.
Constructor Summary | |
---|---|
Extractors()
|
Method Summary | ||
---|---|---|
static
|
cast(java.lang.Object extractorInstance,
java.lang.Class<? extends T> extractedClass)
Returns a type-safe cast of a given extractor instance. |
|
static
|
createExternalExtractor(java.lang.Class<? extends T> objectClass,
java.lang.String command)
Creates an extractor that creates objects from binary data by external command. |
|
static
|
createExternalExtractor(java.lang.Class<? extends T> objectClass,
java.lang.String command,
boolean fileAsArgument)
Creates an extractor that creates objects from binary data by external command. |
|
static Extractor<?> |
createExtractor(java.lang.Class<?> usingClass)
Creates extractor for the provided class. |
|
static
|
createTextExtractor(java.lang.Class<? extends T> objectClass,
java.lang.Object... additionalArguments)
Creates an extractor that creates objects from text InputStream using the constructor that takes BufferedReader as argument. |
|
static
|
extract(Extractor<? extends T> extractor,
java.io.File file)
Extracts object from the file using the given extractor . |
|
static
|
extract(Extractor<? extends T> extractor,
java.net.URL url,
java.lang.String mimeTypeRegexp)
Extracts object downloaded from the url using the given extractor . |
|
static byte[] |
readStreamData(java.io.InputStream inputStream,
int maxBytes)
Read data from input stream into a byte buffer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Extractors()
Method Detail |
---|
public static byte[] readStreamData(java.io.InputStream inputStream, int maxBytes) throws java.io.IOException
maxBytes
parameter is greater than zero, then no more than
maxBytes
will be read from the input stream. Otherwise, the buffer
will contain all the data from the input stream until the end-of-stream.
Note that the stream is not closed
.
inputStream
- the stream from which to read the datamaxBytes
- maximal number of bytes to read from the stream (unlimited if less or equal to zero)
java.io.IOException
- if there was a problem reading from the input streampublic static <T extends LocalAbstractObject> Extractor<T> cast(java.lang.Object extractorInstance, java.lang.Class<? extends T> extractedClass) throws java.lang.ClassCastException
T
- the class of objects the extractor createsextractorInstance
- the instance to castextractedClass
- the class of objects the extractor creates
java.lang.ClassCastException
- if the specified extractorInstance
is not an Extractor
or it extracts an incompatible classpublic static <T extends LocalAbstractObject> T extract(Extractor<? extends T> extractor, java.net.URL url, java.lang.String mimeTypeRegexp) throws ExtractorException
url
using the given extractor
.
T
- the type of object returned by the extractorextractor
- the extractor to use on the dataurl
- the URL from which to download the datamimeTypeRegexp
- regular expression for the mimetype of the data on the given url
url
ExtractorException
- if there was an error reading or extracting the datapublic static <T extends LocalAbstractObject> T extract(Extractor<? extends T> extractor, java.io.File file) throws ExtractorException
file
using the given extractor
.
T
- the type of object returned by the extractorextractor
- the extractor to use on the datafile
- the file from which to load the data
ExtractorException
- if there was an error reading or extracting the datapublic static <T extends LocalAbstractObject> Extractor<T> createTextExtractor(java.lang.Class<? extends T> objectClass, java.lang.Object... additionalArguments) throws java.lang.IllegalArgumentException
BufferedReader
as argument.
T
- the class of object that is created by the extractorobjectClass
- the class of object that is created by the extractoradditionalArguments
- additional arguments for the constructor
java.lang.IllegalArgumentException
- if the objectClass
has no valid constructorpublic static <T extends LocalAbstractObject> Extractor<T> createExternalExtractor(java.lang.Class<? extends T> objectClass, java.lang.String command) throws java.lang.IllegalArgumentException
cmdarray
and is expected to
receive the binary data on its standard input and return the text parsable by
the constructor of objectClass
on its standard output.
T
- the class of object that is created by the extractorobjectClass
- the class of object that is created by the extractorcommand
- the external command (including all necessary arguments)
java.lang.IllegalArgumentException
- if the objectClass
has no valid constructorpublic static <T extends LocalAbstractObject> Extractor<T> createExternalExtractor(java.lang.Class<? extends T> objectClass, java.lang.String command, boolean fileAsArgument) throws java.lang.IllegalArgumentException
cmdarray
and is expected to
receive the binary data on its standard input if fileAsArgument
is true
or the data are read from file that is passed as "%s" argument to the external command if
fileAsArgument
is false.
The extractor must return the text parsable by the constructor of objectClass
on its standard output.
T
- the class of object that is created by the extractorobjectClass
- the class of object that is created by the extractorcommand
- the external command (including all necessary arguments)fileAsArgument
- if true, the "%s" argument of external command is replaced with the filename
java.lang.IllegalArgumentException
- if the objectClass
has no valid constructorpublic static Extractor<?> createExtractor(java.lang.Class<?> usingClass)
LocalAbstractObject
, a
text extractor
is returned.
If the class implements Extractor
interface, a new instance
of this class is returned (using nullary constructor).
usingClass
- the class used to create the extractor
usingClass
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |