Class RawRtfParser

  • All Implemented Interfaces:
    IRtfParser

    public class RawRtfParser
    extends java.lang.Object
    implements IRtfParser
    This class implements a low level RTF parser. It performs the minimum amount of processing on the data read from an RTF file, just passing the caller a stream of events representing the commands and character bytes. In particular the parser doesn't not deal with character encodings or the various Unicode related commands which may be present in an RTF file. This code is based on the approach outlined in the sample C code provided in the RTF Specification 1.9.1 (http://www.microsoft.com/en-gb/download/details.aspx?id=10725)
    • Constructor Detail

      • RawRtfParser

        public RawRtfParser()
    • Method Detail

      • parse

        public void parse​(IRtfSource source,
                          IRtfListener listener)
                   throws java.io.IOException
        Parse RTF data from an input source.
        Specified by:
        parse in interface IRtfParser
        Throws:
        java.io.IOException
      • handleCharacterByte

        private void handleCharacterByte​(int ch)
                                  throws java.io.IOException
        Process a single character byte, or hex encoded character byte.
        Throws:
        java.io.IOException
      • handleCommand

        private void handleCommand()
                            throws java.io.IOException
        Read and process an RTF command.
        Throws:
        java.io.IOException
      • handleCommand

        private void handleCommand​(java.lang.StringBuilder commandBuffer,
                                   int parameter,
                                   boolean hasParameter)
                            throws java.io.IOException
        Determine what to do with the extracted command.
        Throws:
        java.io.IOException
      • handleCharacterData

        private void handleCharacterData()
        Pass accumulated character data to the listener.
      • handleBinaryData

        private void handleBinaryData​(int size)
                               throws java.io.IOException
        Pass binary data to the listener.
        Throws:
        java.io.IOException
      • handleGroupStart

        private void handleGroupStart()
        Inform the listener of a group start.
      • handleGroupEnd

        private void handleGroupEnd()
        Inform the listener of a group end.