Class RtfStringSource

  • All Implemented Interfaces:
    IRtfSource

    public class RtfStringSource
    extends java.lang.Object
    implements IRtfSource
    This is a hack... as a convenience it allows RTF data held in a string to be parsed. The reason it's a hack is that RTF commands are used to manage character encoding, and it's unlikely that the caller handled this when they read the RTF in to the string from its original source. It is also possible for an RTF file to contain raw binary data, which this class will definitely not deal with. Having said all of that, in the vast majority of cases this approach will work fine. It's also more efficient than creating an InputStream from a String - which usually involves duplicating byte arrays.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String data  
      private int index  
    • Constructor Summary

      Constructors 
      Constructor Description
      RtfStringSource​(java.lang.String data)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int read()
      Read a single byte.
      int read​(byte[] b)
      Read enough bytes to fill the array.
      void unread​(int c)
      Push back a single byte to allow it to be read again by the parser.
      • Methods inherited from class java.lang.Object

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

      • data

        private final java.lang.String data
      • index

        private int index
    • Constructor Detail

      • RtfStringSource

        public RtfStringSource​(java.lang.String data)
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Description copied from interface: IRtfSource
        Read a single byte.
        Specified by:
        read in interface IRtfSource
        Throws:
        java.io.IOException
      • unread

        public void unread​(int c)
                    throws java.io.IOException
        Description copied from interface: IRtfSource
        Push back a single byte to allow it to be read again by the parser.
        Specified by:
        unread in interface IRtfSource
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Description copied from interface: IRtfSource
        Read enough bytes to fill the array.
        Specified by:
        read in interface IRtfSource
        Throws:
        java.io.IOException