info.bioinfweb.jphyloio.formats.text

## Class AbstractTextEventReader<P extends TextReaderStreamDataProvider<? extends AbstractTextEventReader<P>>>

- java.lang.Object
- - info.bioinfweb.jphyloio.AbstractEventReader<P>
  - - info.bioinfweb.jphyloio.formats.text.AbstractTextEventReader<P>

- All Implemented Interfaces:
    JPhyloIOEventReader, JPhyloIOFormatSpecificObject, ReadWriteConstants
  Direct Known Subclasses:
    AbstractPhylipEventReader, FASTAEventReader, MEGAEventReader, NewickEventReader, NexusEventReader

      public abstract class AbstractTextEventReader<P extends TextReaderStreamDataProvider<? extends AbstractTextEventReader<P>>>
      extends AbstractEventReader<P>

  Abstract base class for all readers that read their data from a file using a `PeekReader`.

  Those are currently readers all reader reading non-XML formats from text files.

  Author:
    Ben Stöver

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected boolean` | `lineConsumed`

    - ### Fields inherited from interface info.bioinfweb.jphyloio.ReadWriteConstants

      `ATTRIBUTE_STRING_KEY, ATTRIBUTES_NAMESPACE_FOLDER, DATA_TYPE_NAMESPACE_FOLDER, DATA_TYPE_SIMPLE_VALUE_LIST, DEFAULT_CHAR_SET_ID_PREFIX, DEFAULT_CHARACTER_DEFINITION_ID_PREFIX, DEFAULT_EDGE_ID_PREFIX, DEFAULT_GENERAL_ID_PREFIX, DEFAULT_MATRIX_ID_PREFIX, DEFAULT_MAX_COMMENT_LENGTH, DEFAULT_MAX_TOKENS_TO_READ, DEFAULT_META_ID_PREFIX, DEFAULT_NETWORK_ID_PREFIX, DEFAULT_NODE_EDGE_SET_ID_PREFIX, DEFAULT_NODE_ID_PREFIX, DEFAULT_OTU_ID_PREFIX, DEFAULT_OTU_LIST_ID_PREFIX, DEFAULT_OTU_SET_ID_PREFIX, DEFAULT_SEQUENCE_ID_PREFIX, DEFAULT_SEQUENCE_SET_ID_PREFIX, DEFAULT_TOKEN_DEFINITION_ID_PREFIX, DEFAULT_TOKEN_SET_ID_PREFIX, DEFAULT_TREE_ID_PREFIX, DEFAULT_TREE_NETWORK_GROUP_ID_PREFIX, DEFAULT_TREE_NETWORK_SET_ID_PREFIX, JPHYLOIO_ATTRIBUTES_NAMESPACE, JPHYLOIO_ATTRIBUTES_PREFIX, JPHYLOIO_DATA_TYPE_NAMESPACE, JPHYLOIO_DATA_TYPE_PREFIX, JPHYLOIO_FORMATS_NAMESPACE_PREFIX, JPHYLOIO_GENERAL_NAMESPACE, JPHYLOIO_NAMESPACE_PREFIX, JPHYLOIO_PREDICATE_NAMESPACE, JPHYLOIO_PREDICATE_PREFIX, PREDICATE_CHARACTER_COUNT, PREDICATE_EDGE_LENGTH, PREDICATE_EDGE_SOURCE_NODE, PREDICATE_EDGE_TARGET_NODE, PREDICATE_HAS_CUSTOM_XML, PREDICATE_HAS_LITERAL_METADATA, PREDICATE_HAS_RESOURCE_METADATA, PREDICATE_IS_CROSSLINK, PREDICATE_NAMESPACE_FOLDER, PREDICATE_PART_SEPERATOR, PREDICATE_SEQUENCE_COUNT, RESERVED_ID_PREFIX`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractTextEventReader(java.io.File file, ReadWriteParameterMap parameters, java.lang.String matchToken)` Creates a new instance of this class.
    `AbstractTextEventReader(java.io.InputStream stream, ReadWriteParameterMap parameters, java.lang.String matchToken)` Creates a new instance of this class.
    `AbstractTextEventReader(PeekReader reader, ReadWriteParameterMap parameters, java.lang.String matchToken)` Creates a new instance of this class.
    `AbstractTextEventReader(java.io.Reader reader, ReadWriteParameterMap parameters, java.lang.String matchToken)` Creates a new instance of this class.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()` Closes the underlying document source (usually a stream).
    `protected void` | `consumeWhiteSpaceAndComments(char commentStart, char commentEnd)`
    `protected P` | `createStreamDataProvider()` This method is called in the constructor of `AbstractEventReader` to initialize the stream data provider that will be returned by `AbstractEventReader.getStreamDataProvider()`.
    `protected java.util.List<java.lang.String>` | `createTokenList(java.lang.CharSequence sequence)`
    `protected PeekReader` | `getReader()` Returns the reader providing the document contents.
    `protected JPhyloIOEvent` | `readCharacters(java.lang.String currentSequenceName)`
    `protected JPhyloIOEvent` | `readCharacters(java.lang.String currentSequenceName, char commentStart, char commentEnd)` Reads characters from the stream and adds a respective sequence tokens event to the queue.
    `protected void` | `readComment(char commentStart, char commentEnd)` Reads a single comment from the reader.
    `protected KeyValueInformation` | `readKeyValueInformation(char commandEnd, char commentStart, char commentEnd, char keyValueSeparator)`
    `protected java.lang.String` | `readToken(char commandEnd, char commentStart, char commentEnd, char keyValueSeparator)`

    - ### Methods inherited from class info.bioinfweb.jphyloio.AbstractEventReader

      `addEventListener, fireEvent, getCurrentEventCollection, getIDManager, getLastNonCommentEvent, getParameters, getParentInformation, getPreviousEvent, getSequenceTokensEventManager, getStreamDataProvider, getUpcomingEvents, hasNextEvent, hasSpecialEventCollection, isBeforeFirstAccess, next, nextOfType, peek, readNextEvent, removeEventListener, resetCurrentEventCollection, setCurrentEventCollection`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface info.bioinfweb.jphyloio.JPhyloIOFormatSpecificObject

      `getFormatID`

- - ### Field Detail

    - #### lineConsumed

          protected boolean lineConsumed

  - ### Constructor Detail

    - #### AbstractTextEventReader

          public AbstractTextEventReader(PeekReader reader,
                                         ReadWriteParameterMap parameters,
                                         java.lang.String matchToken)

      Creates a new instance of this class.
      Parameters:
        `reader` - the reader providing the document data to be read
        `parameters` - the parameter map for this reader instance
        `matchToken` - the match token to be replaced in sequences or `null` if no replacement shall be performed

    - #### AbstractTextEventReader

          public AbstractTextEventReader(java.io.Reader reader,
                                         ReadWriteParameterMap parameters,
                                         java.lang.String matchToken)
                                  throws java.io.IOException

      Creates a new instance of this class.
      Parameters:
        `reader` - the reader providing the document data to be read
        `parameters` - the parameter map for this reader instance
        `matchToken` - the match token to be replaced in sequences or `null` if no replacement shall be performed
      Throws:
        `java.io.IOException`

    - #### AbstractTextEventReader

          public AbstractTextEventReader(java.io.InputStream stream,
                                         ReadWriteParameterMap parameters,
                                         java.lang.String matchToken)
                                  throws java.io.IOException

      Creates a new instance of this class.
      Parameters:
        `stream` - the stream providing the document data to be read
        `parameters` - the parameter map for this reader instance
        `matchToken` - the match token to be replaced in sequences or `null` if no replacement shall be performed
      Throws:
        `java.io.IOException`

    - #### AbstractTextEventReader

          public AbstractTextEventReader(java.io.File file,
                                         ReadWriteParameterMap parameters,
                                         java.lang.String matchToken)
                                  throws java.io.IOException

      Creates a new instance of this class.
      Parameters:
        `file` - the document file to be read
        `parameters` - the parameter map for this reader instance
        `matchToken` - the match token to be replaced in sequences or `null` if no replacement shall be performed
      Throws:
        `java.io.IOException`

  - ### Method Detail

    - #### createStreamDataProvider

          protected P createStreamDataProvider()

      Description copied from class: `AbstractEventReader`
      This method is called in the constructor of `AbstractEventReader` to initialize the stream data provider that will be returned by `AbstractEventReader.getStreamDataProvider()`. Inherit classes that use their own stream data provider implementation should overwrite this method.

      This default implementation creates a new instance of `ReaderStreamDataProvider`.

      Overrides:
        `createStreamDataProvider` in class `AbstractEventReader<P extends TextReaderStreamDataProvider<? extends AbstractTextEventReader<P>>>`
      Returns:
        the stream data provider to be used with this instance

    - #### createTokenList

          protected java.util.List<java.lang.String> createTokenList(java.lang.CharSequence sequence)

    - #### consumeWhiteSpaceAndComments

          protected void consumeWhiteSpaceAndComments(char commentStart,
                                                      char commentEnd)
                                               throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### readComment

          protected void readComment(char commentStart,
                                     char commentEnd)
                              throws java.io.IOException

      Reads a single comment from the reader. Only the first one of subsequent comments (e.g. `[comment 1][comment 2]`) would be read. Nested comments are included in the parsed comment.

      This method assumes that the comment start symbol has already been consumed.

      Throws:
        `java.io.IOException`

    - #### readCharacters

          protected JPhyloIOEvent readCharacters(java.lang.String currentSequenceName)
                                          throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### readCharacters

          protected JPhyloIOEvent readCharacters(java.lang.String currentSequenceName,
                                                 char commentStart,
                                                 char commentEnd)
                                          throws java.io.IOException

      Reads characters from the stream and adds a respective sequence tokens event to the queue. Additionally comment events are added to the queue, if comments are found.
      Parameters:
        `currentSequenceName` -
        `commentStart` -
        `commentEnd` -
      Returns:
        the sequence tokens event that was added to the event queue
      Throws:
        `java.lang.Exception`
        `java.io.IOException`

    - #### readToken

          protected java.lang.String readToken(char commandEnd,
                                               char commentStart,
                                               char commentEnd,
                                               char keyValueSeparator)
                                        throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### readKeyValueInformation

          protected KeyValueInformation readKeyValueInformation(char commandEnd,
                                                                char commentStart,
                                                                char commentEnd,
                                                                char keyValueSeparator)
                                                         throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### getReader

          protected PeekReader getReader()

      Returns the reader providing the document contents.
      Returns:
        the reader to read the document data from

    - #### close

          public void close()
                     throws java.io.IOException

      Description copied from interface: `JPhyloIOEventReader`
      Closes the underlying document source (usually a stream).
      Specified by:
        `close` in interface `JPhyloIOEventReader`
      Overrides:
        `close` in class `AbstractEventReader<P extends TextReaderStreamDataProvider<? extends AbstractTextEventReader<P>>>`
      Throws:
        `java.io.IOException` - Implementing classes might throw different types of exceptions if the stream cannot be closed properly