Package ome.services.fulltext
Class FileParser
- java.lang.Object
-
- ome.services.fulltext.FileParser
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
PdfParser
public class FileParser extends java.lang.Object implements org.springframework.context.ApplicationContextAware
Object which attempts to parse any file given to it. On an exception or empty/missing file, an emptyIterable
should be returned rather than throwing an exception. Subclasses should follow- Since:
- 3.0-Beta3
-
-
Field Summary
Fields Modifier and Type Field Description protected ome.system.OmeroContext
context
static java.lang.Iterable<java.io.Reader>
EMPTY
Iterable
which returns an emptyIterator
.protected long
maxFileSize
-
Constructor Summary
Constructors Constructor Description FileParser()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Iterable<java.io.Reader>
doParse(java.io.File file)
Template method to parse aFile
into manageable chunks.java.lang.Iterable<java.io.Reader>
parse(java.io.File file)
UsesdoParse(File)
to create manageable chunks of a file for indexing.void
setApplicationContext(org.springframework.context.ApplicationContext arg0)
void
setMaxFileSize(java.lang.Long size)
java.lang.Iterable<java.io.Reader>
wrap(java.io.Reader r)
java.lang.Iterable<java.io.Reader>
wrap(java.util.Iterator<java.io.Reader> it)
Wraps anIterator
with anIterable
instance.
-
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext arg0) throws org.springframework.beans.BeansException
- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
setMaxFileSize
public void setMaxFileSize(java.lang.Long size)
-
parse
public final java.lang.Iterable<java.io.Reader> parse(java.io.File file)
UsesdoParse(File)
to create manageable chunks of a file for indexing. If theFile
argument is null or unreadable, then theEMPTY
Iterable
will be returned. The same holds if a nullIterable
is returned or anException
is thrown. TheIterator
returned from the instance should always be completely iterated through so that resources can be released. For example,for (String string : parse(file)) { /* possibly ignore string *\/ }
- Parameters:
file
- Can be null.- Returns:
- An
Iterable
which is never null.
-
doParse
public java.lang.Iterable<java.io.Reader> doParse(java.io.File file) throws java.lang.Exception
Template method to parse aFile
into manageable chunks. The default implementation reads from the file lazily with chunks overlapping on the final white space. For example a file with:The quick brown fox jumps over the lazy dog
might be parsed to:The quick brown fox jumps
andjumps over the lazy dog
. Receives a non-null,readable
File
instance fromparse(File)
and can return a possible nullIterable
or throw anException
. In any of the non-successful cases, theEMPTY
Iterable
will be returned to the consumer.- Throws:
java.lang.Exception
-
wrap
public java.lang.Iterable<java.io.Reader> wrap(java.util.Iterator<java.io.Reader> it)
Wraps anIterator
with anIterable
instance. If theIterator
is null, theEMPTY
Iterable
will be returned.- Parameters:
it
- Can be null.- Returns:
- Will never be null
-
wrap
public java.lang.Iterable<java.io.Reader> wrap(java.io.Reader r)
-
-