Class RtfToText

java.lang.Object
org.fife.ui.rsyntaxtextarea.RtfToText

final class RtfToText extends Object
Gets the plain text version of RTF documents.

This is used by StyledTextTransferable to return the plain text version of the transferable when the receiver does not support RTF.

Version:
1.0
  • Field Details

    • r

      private Reader r
    • sb

      private StringBuilder sb
    • controlWord

      private StringBuilder controlWord
    • blockCount

      private int blockCount
    • inControlWord

      private boolean inControlWord
  • Constructor Details

    • RtfToText

      private RtfToText(Reader r)
      Private constructor.
      Parameters:
      r - The reader to read RTF text from.
  • Method Details

    • convert

      private String convert() throws IOException
      Converts the RTF text read from this converter's Reader into plain text. It is the caller's responsibility to close the reader after this method is called.
      Returns:
      The plain text.
      Throws:
      IOException - If an IO error occurs.
    • endControlWord

      private void endControlWord()
      Ends a control word. Checks whether it is a common one that affects the plain text output (such as "par" or "tab") and updates the text buffer accordingly.
    • isUnicodeEscape

      private static boolean isUnicodeEscape(String controlWord)
    • getPlainText

      public static String getPlainText(byte[] rtf) throws IOException
      Converts the contents of the specified byte array representing an RTF document into plain text.
      Parameters:
      rtf - The byte array representing an RTF document.
      Returns:
      The contents of the RTF document, in plain text.
      Throws:
      IOException - If an IO error occurs.
    • getPlainText

      public static String getPlainText(File file) throws IOException
      Converts the contents of the specified RTF file to plain text.
      Parameters:
      file - The RTF file to convert.
      Returns:
      The contents of the file, in plain text.
      Throws:
      IOException - If an IO error occurs.
    • getPlainText

      public static String getPlainText(InputStream in) throws IOException
      Converts the contents of the specified input stream to plain text. The input stream will be closed when this method returns.
      Parameters:
      in - The input stream to convert. This will be closed when this method returns.
      Returns:
      The contents of the stream, in plain text.
      Throws:
      IOException - If an IO error occurs.
    • getPlainText

      private static String getPlainText(Reader r) throws IOException
      Converts the contents of the specified Reader to plain text.
      Parameters:
      r - The Reader. This will be closed when this method returns.
      Returns:
      The contents of the Reader, in plain text.
      Throws:
      IOException - If an IO error occurs.
    • getPlainText

      public static String getPlainText(String rtf) throws IOException
      Converts the contents of the specified String to plain text.
      Parameters:
      rtf - A string whose contents represent an RTF document.
      Returns:
      The contents of the String, in plain text.
      Throws:
      IOException - If an IO error occurs.