Class AbstractReader

  • All Implemented Interfaces:
    java.lang.Iterable<java.lang.String>, java.util.Iterator<java.lang.String>
    Direct Known Subclasses:
    PPCReader, RJEReader

    public abstract class AbstractReader
    extends java.lang.Object
    implements java.util.Iterator<java.lang.String>, java.lang.Iterable<java.lang.String>
    Base class for message reader iterators.
    Since:
    7.8
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.io.Reader reader
      The wrapped reader instance.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractReader​(java.io.File file)
      Constructs a reader to read messages from a file
      AbstractReader​(java.io.File _file, java.nio.charset.Charset _charset)  
      AbstractReader​(java.io.InputStream stream)
      Constructs a reader to read messages from a stream
      AbstractReader​(java.io.InputStream _stream, java.nio.charset.Charset _charset)  
      AbstractReader​(java.io.Reader r)
      Constructs a reader to read messages from a given Reader instance
      AbstractReader​(java.lang.String string)
      Constructs a reader to read messages from a string
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract boolean hasNext()  
      java.util.Iterator<java.lang.String> iterator()  
      abstract java.lang.String next()  
      AbstractMT nextMT()
      Reads the next raw content from the iterator and returns the message parsed into an MT.
      SwiftMessage nextSwiftMessage()
      Reads the next raw content from the iterator and returns the message parsed as a generic SwiftMessage.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from interface java.util.Iterator

        forEachRemaining, remove
    • Field Detail

      • reader

        protected java.io.Reader reader
        The wrapped reader instance.
    • Constructor Detail

      • AbstractReader

        public AbstractReader​(java.io.Reader r)
        Constructs a reader to read messages from a given Reader instance
        Parameters:
        r - reader instance
      • AbstractReader

        public AbstractReader​(java.lang.String string)
        Constructs a reader to read messages from a string
        Parameters:
        string - String providing the character stream.
        Throws:
        java.lang.IllegalArgumentException - if string is null
      • AbstractReader

        public AbstractReader​(java.io.InputStream stream)
        Constructs a reader to read messages from a stream
        Parameters:
        stream - input stream
        Throws:
        java.lang.IllegalArgumentException - if stream is null
      • AbstractReader

        public AbstractReader​(java.io.InputStream _stream,
                              java.nio.charset.Charset _charset)
      • AbstractReader

        public AbstractReader​(java.io.File file)
                       throws java.io.FileNotFoundException
        Constructs a reader to read messages from a file
        Parameters:
        file - file
        Throws:
        java.io.FileNotFoundException - if the file does not exist, is a directory or cannot be opened
        java.lang.IllegalArgumentException - if file is null
      • AbstractReader

        public AbstractReader​(java.io.File _file,
                              java.nio.charset.Charset _charset)
                       throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
    • Method Detail

      • next

        public abstract java.lang.String next()
        Specified by:
        next in interface java.util.Iterator<java.lang.String>
      • hasNext

        public abstract boolean hasNext()
        Specified by:
        hasNext in interface java.util.Iterator<java.lang.String>
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
                                                      throws java.lang.IllegalArgumentException
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>
        Returns:
        this object as an Iterator
        Throws:
        java.lang.IllegalArgumentException - if the iteration is attempted more than once
      • nextMT

        public AbstractMT nextMT()
                          throws java.io.IOException
        Reads the next raw content from the iterator and returns the message parsed into an MT.

        IMPORTANT:
        Since MTnnn model classes are implemented only for system and user-to-user messages (categories 0 to 9) if an ACK/NAK (service id 21) message is found, the MT following the system message is returned (not the ACK/NAK).
        For other service messages (login, select, quit) this method will return null because there is no MT representation to create.
        If you need to deal with all type of messages (including service, system and user-to-user) you can use nextSwiftMessage() instead.

        Returns:
        parsed message or null if content is blank
        Throws:
        java.io.IOException - if the message content cannot be parsed into an MT
      • nextSwiftMessage

        public SwiftMessage nextSwiftMessage()
                                      throws java.io.IOException
        Reads the next raw content from the iterator and returns the message parsed as a generic SwiftMessage. This method is convenient where the RJE content can include any type of message including service messages, system messages and user-to-user messages.
        Returns:
        parsed message or null if content is blank
        Throws:
        java.io.IOException - if the message content cannot be parsed into a SwiftMessage
        Since:
        7.8.3