APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing.text.rtf

pack-priv abstract Class RTFParser

extends AbstractFilter
Class Inheritance
Known Direct Subclasses
javax.swing.text.rtf.RTFReader
Imports
java.io.*, java.lang.*, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.CharsetDecoder, .CoderResult

RTFParser is a subclass of AbstractFilter which understands basic RTF syntax and passes a stream of control words, text, and begin/end group indications to its subclass. Normally programmers will only use RTFReader, a subclass of this class that knows what to do with the tokens this class parses.
See Also
AbstractFilter, RTFReader

Field Summary

Modifier and TypeField and Description
private byte[]
pack-priv ByteArrayOutputStream
private long
private char[]
private StringBuffer
protected CharsetDecoder
protected ByteBuffer
private CharBuffer
public int
level

The current RTF group nesting level.

private int
private String
pack-priv static final char
pack-priv static final boolean[]
private final int
private final int
private final int
private final int
private final int
private final int
private final int
private boolean[]
private int
protected PrintStream
warnings

A stream to which to write warnings and debugging information while parsing.

Inherited from javax.swing.text.rtf.AbstractFilter:
allSpecialsTablelatin1TranslationTablenoSpecialsTablespecialsTabletranslationTable

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract void
begingroup()

Implemented by subclasses to react to an increase in the nesting level.

public void
close()

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes the parser.

private char
decode(char ch)

public abstract void
endgroup()

Implemented by subclasses to react to the end of a group.

public void
flush()

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes any buffered but not yet written characters.

public abstract void
handleBinaryBlob(byte[] data)

Implemented by subclasses to handle the contents of the \bin keyword.

public abstract boolean
handleKeyword(String keyword)

Implemented by subclasses to interpret a parameter-less RTF keyword.

public abstract boolean
handleKeyword(String
The keyword, as with handleKeyword(String).
keyword
,
int
The parameter following the keyword.
parameter
)

Implemented by subclasses to interpret a keyword with a parameter.

public abstract void
handleText(String text)

Implemented by subclasses to interpret text from the RTF stream.

public void
handleText(char ch)

protected void
public void
write(String s)

Overrides javax.swing.text.rtf.AbstractFilter.write.

Hopefully, all subclasses will override this method to accept strings of text, but if they don't, AbstractFilter's implementation will spoon-feed them via write(char).

public void
write(char ch)

Implements abstract javax.swing.text.rtf.AbstractFilter.write.

Subclasses must provide an implementation of this method which accepts a single (non-special) character.

public void
writeSpecial(int b)

Implements abstract javax.swing.text.rtf.AbstractFilter.writeSpecial.

Subclasses must provide an implementation of this method which accepts a single special byte.

Inherited from javax.swing.text.rtf.AbstractFilter:
readFromReaderreadFromStreamwritewrite

Field Detail

baback to summary
private byte[] ba
binaryBufback to summary
pack-priv ByteArrayOutputStream binaryBuf
binaryBytesLeftback to summary
private long binaryBytesLeft
caback to summary
private char[] ca
currentCharactersback to summary
private StringBuffer currentCharacters
decoderback to summary
protected CharsetDecoder decoder
decoderBBback to summary
protected ByteBuffer decoderBB
decoderCBback to summary
private CharBuffer decoderCB
levelback to summary
public int level

The current RTF group nesting level.

pendingCharacterback to summary
private int pendingCharacter
pendingKeywordback to summary
private String pendingKeyword
REPLACEMENT_CHARback to summary
pack-priv static final char REPLACEMENT_CHAR
rtfSpecialsTableback to summary
pack-priv static final boolean[] rtfSpecialsTable
S_aftertickback to summary
private final int S_aftertick
S_aftertickcback to summary
private final int S_aftertickc
S_backslashedback to summary
private final int S_backslashed
S_inblobback to summary
private final int S_inblob
S_parameterback to summary
private final int S_parameter
S_textback to summary
private final int S_text
S_tokenback to summary
private final int S_token
savedSpecialsback to summary
private boolean[] savedSpecials
stateback to summary
private int state
warningsback to summary
protected PrintStream warnings

A stream to which to write warnings and debugging information while parsing. This is set to System.out to log any anomalous information to stdout.

Constructor Detail

RTFParserback to summary
public RTFParser()

Method Detail

begingroupback to summary
public abstract void begingroup()

Implemented by subclasses to react to an increase in the nesting level.

closeback to summary
public void close() throws IOException

Overrides java.io.OutputStream.close.

Implements java.io.Closeable.close.

Closes the parser. Currently, this simply does a flush(), followed by some minimal consistency checks.

Exceptions
IOException:

Doc from java.io.OutputStream.close.

if an I/O error occurs.

decodeback to summary
private char decode(char ch)
endgroupback to summary
public abstract void endgroup()

Implemented by subclasses to react to the end of a group.

flushback to summary
public void flush() throws IOException

Overrides java.io.OutputStream.flush.

Implements java.io.Flushable.flush.

Flushes any buffered but not yet written characters. Subclasses which override this method should call this method before flushing any of their own buffers.

Exceptions
IOException:

Doc from java.io.OutputStream.flush.

if an I/O error occurs.

handleBinaryBlobback to summary
public abstract void handleBinaryBlob(byte[] data)

Implemented by subclasses to handle the contents of the \bin keyword.

handleKeywordback to summary
public abstract boolean handleKeyword(String keyword)

Implemented by subclasses to interpret a parameter-less RTF keyword. The keyword is passed without the leading '/' or any delimiting whitespace.

handleKeywordback to summary
public abstract boolean handleKeyword(String keyword, int parameter)

Implemented by subclasses to interpret a keyword with a parameter.

Parameters
keyword:String

The keyword, as with handleKeyword(String).

parameter:int

The parameter following the keyword.

handleTextback to summary
public abstract void handleText(String text)

Implemented by subclasses to interpret text from the RTF stream.

handleTextback to summary
public void handleText(char ch)
warningback to summary
protected void warning(String s)
writeback to summary
public void write(String s) throws IOException

Overrides javax.swing.text.rtf.AbstractFilter.write.

Doc from javax.swing.text.rtf.AbstractFilter.write.

Hopefully, all subclasses will override this method to accept strings of text, but if they don't, AbstractFilter's implementation will spoon-feed them via write(char).

writeback to summary
public void write(char ch) throws IOException

Implements abstract javax.swing.text.rtf.AbstractFilter.write.

Doc from javax.swing.text.rtf.AbstractFilter.write.

Subclasses must provide an implementation of this method which accepts a single (non-special) character.

Annotations
@SuppressWarnings:fallthrough
writeSpecialback to summary
public void writeSpecial(int b) throws IOException

Implements abstract javax.swing.text.rtf.AbstractFilter.writeSpecial.

Doc from javax.swing.text.rtf.AbstractFilter.writeSpecial.

Subclasses must provide an implementation of this method which accepts a single special byte. No translation is performed on specials.