Class 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 empty Iterable 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 empty Iterator.
      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 a File into manageable chunks.
      java.lang.Iterable<java.io.Reader> parse​(java.io.File file)
      Uses doParse(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 an Iterator with an Iterable instance.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • context

        protected ome.system.OmeroContext context
      • maxFileSize

        protected long maxFileSize
      • EMPTY

        public static final java.lang.Iterable<java.io.Reader> EMPTY
        Iterable which returns an empty Iterator. This will be used in case
    • Constructor Detail

      • FileParser

        public FileParser()
    • Method Detail

      • setApplicationContext

        public void setApplicationContext​(org.springframework.context.ApplicationContext arg0)
                                   throws org.springframework.beans.BeansException
        Specified by:
        setApplicationContext in interface org.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)
        Uses doParse(File) to create manageable chunks of a file for indexing. If the File argument is null or unreadable, then the EMPTY Iterable will be returned. The same holds if a null Iterable is returned or an Exception is thrown. The Iterator 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 a File 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 and jumps over the lazy dog. Receives a non-null, readable File instance from parse(File) and can return a possible null Iterable or throw an Exception. In any of the non-successful cases, the EMPTY 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 an Iterator with an Iterable instance. If the Iterator is null, the EMPTY 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)