Class CharFilter

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable
    Direct Known Subclasses:
    BaseCharFilter, PersianCharFilter

    public abstract class CharFilter
    extends java.io.Reader
    Subclasses of CharFilter can be chained to filter a Reader They can be used as Reader with additional offset correction. Tokenizers will automatically use correctOffset(int) if a CharFilter subclass is used.

    This class is abstract: at a minimum you must implement Reader.read(char[], int, int), transforming the input in some way from input, and correct(int) to adjust the offsets to match the originals.

    You can optionally provide more efficient implementations of additional methods like Reader.read(), Reader.read(char[]), Reader.read(java.nio.CharBuffer), but this is not required.

    For examples and integration with Analyzer, see the Analysis package documentation.

    • Constructor Summary

      Constructors 
      Constructor Description
      CharFilter​(java.io.Reader input)
      Create a new CharFilter wrapping the provided reader.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes the underlying input stream.
      int correctOffset​(int currentOff)
      Chains the corrected offset through the input CharFilter(s).
      • Methods inherited from class java.io.Reader

        mark, markSupported, nullReader, read, read, read, read, ready, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CharFilter

        public CharFilter​(java.io.Reader input)
        Create a new CharFilter wrapping the provided reader.
        Parameters:
        input - a Reader, can also be a CharFilter for chaining.
    • Method Detail

      • close

        public void close()
                   throws java.io.IOException
        Closes the underlying input stream.

        NOTE: The default implementation closes the input Reader, so be sure to call super.close() when overriding this method.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in class java.io.Reader
        Throws:
        java.io.IOException
      • correctOffset

        public final int correctOffset​(int currentOff)
        Chains the corrected offset through the input CharFilter(s).