Package org.fife.ui.rsyntaxtextarea
Class RtfToText
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.RtfToText
-
final class RtfToText extends java.lang.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 Summary
Fields Modifier and Type Field Description private int
blockCount
private java.lang.StringBuilder
controlWord
private boolean
inControlWord
private java.io.Reader
r
private java.lang.StringBuilder
sb
-
Constructor Summary
Constructors Modifier Constructor Description private
RtfToText(java.io.Reader r)
Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
convert()
Converts the RTF text read from this converter'sReader
into plain text.private void
endControlWord()
Ends a control word.static java.lang.String
getPlainText(byte[] rtf)
Converts the contents of the specified byte array representing an RTF document into plain text.static java.lang.String
getPlainText(java.io.File file)
Converts the contents of the specified RTF file to plain text.static java.lang.String
getPlainText(java.io.InputStream in)
Converts the contents of the specified input stream to plain text.private static java.lang.String
getPlainText(java.io.Reader r)
Converts the contents of the specifiedReader
to plain text.static java.lang.String
getPlainText(java.lang.String rtf)
Converts the contents of the specified String to plain text.private static boolean
isUnicodeEscape(java.lang.String controlWord)
-
-
-
Method Detail
-
convert
private java.lang.String convert() throws java.io.IOException
Converts the RTF text read from this converter'sReader
into plain text. It is the caller's responsibility to close the reader after this method is called.- Returns:
- The plain text.
- Throws:
java.io.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(java.lang.String controlWord)
-
getPlainText
public static java.lang.String getPlainText(byte[] rtf) throws java.io.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:
java.io.IOException
- If an IO error occurs.
-
getPlainText
public static java.lang.String getPlainText(java.io.File file) throws java.io.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:
java.io.IOException
- If an IO error occurs.
-
getPlainText
public static java.lang.String getPlainText(java.io.InputStream in) throws java.io.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:
java.io.IOException
- If an IO error occurs.
-
getPlainText
private static java.lang.String getPlainText(java.io.Reader r) throws java.io.IOException
Converts the contents of the specifiedReader
to plain text.- Parameters:
r
- TheReader
. This will be closed when this method returns.- Returns:
- The contents of the
Reader
, in plain text. - Throws:
java.io.IOException
- If an IO error occurs.
-
getPlainText
public static java.lang.String getPlainText(java.lang.String rtf) throws java.io.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:
java.io.IOException
- If an IO error occurs.
-
-