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

pack-priv abstract Class AbstractFilter

extends OutputStream
Class Inheritance
Known Direct Subclasses
javax.swing.text.rtf.RTFParser
Imports
java.io.*, java.lang.*

A generic superclass for streams which read and parse text consisting of runs of characters interspersed with occasional ``specials'' (formatting characters).

Most of the functionality of this class would be redundant except that the ByteToChar converters are suddenly private API. Presumably this class will disappear when the API is made public again. (sigh) That will also let us handle multibyte character sets...

A subclass should override at least write(char) and writeSpecial(int). For efficiency's sake it's a good idea to override write(String) as well. The subclass' initializer may also install appropriate translation and specials tables.

See Also
OutputStream

Field Summary

Modifier and TypeField and Description
pack-priv static final boolean[]
allSpecialsTable

A specials table which indicates that all characters are special

pack-priv static final char[]
latin1TranslationTable

A translation table which does ISO Latin-1 (trivial)

pack-priv static final boolean[]
noSpecialsTable

A specials table which indicates that no characters are special

protected boolean[]
specialsTable

A table indicating which byte values should be interpreted as characters and which should be treated as formatting codes

protected char[]
translationTable

A table mapping bytes to characters

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
readFromStream(InputStream
An InputStream providing text.
in
)

A convenience method that reads text from a FileInputStream and writes it to the receiver.

public void
write(int b)

Implements abstract java.io.OutputStream.write.

Implements the abstract method of OutputStream, of which this class is a subclass.

public void
write(byte[] buf, int off, int len)

Overrides java.io.OutputStream.write.

Implements the buffer-at-a-time write method for greater efficiency.

public void
write(String
The string of non-special characters written to the OutputStream.
s
)

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).

protected abstract void
write(char
The character written to the OutputStream.
ch
)

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

protected abstract void
writeSpecial(int
The byte written to the OutputStream.
b
)

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

Inherited from java.io.OutputStream:
closeflushnullOutputStreamwrite

Field Detail

allSpecialsTableback to summary
pack-priv static final boolean[] allSpecialsTable

A specials table which indicates that all characters are special

latin1TranslationTableback to summary
pack-priv static final char[] latin1TranslationTable

A translation table which does ISO Latin-1 (trivial)

noSpecialsTableback to summary
pack-priv static final boolean[] noSpecialsTable

A specials table which indicates that no characters are special

specialsTableback to summary
protected boolean[] specialsTable

A table indicating which byte values should be interpreted as characters and which should be treated as formatting codes

translationTableback to summary
protected char[] translationTable

A table mapping bytes to characters

Constructor Detail

AbstractFilterback to summary
public AbstractFilter()

Method Detail

readFromReaderback to summary
public void readFromReader(Reader in) throws IOException
readFromStreamback to summary
public void readFromStream(InputStream in) throws IOException

A convenience method that reads text from a FileInputStream and writes it to the receiver. The format in which the file is read is determined by the concrete subclass of AbstractFilter to which this method is sent.

This method does not close the receiver after reaching EOF on the input stream. The user must call close() to ensure that all data are processed.

Parameters
in:InputStream

An InputStream providing text.

writeback to summary
public void write(int b) throws IOException

Implements abstract java.io.OutputStream.write.

Implements the abstract method of OutputStream, of which this class is a subclass.

Exceptions
IOException:

Doc from java.io.OutputStream.write.

if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

writeback to summary
public void write(byte[] buf, int off, int len) throws IOException

Overrides java.io.OutputStream.write.

Implements the buffer-at-a-time write method for greater efficiency.

PENDING: Does write(byte[]) call write(byte[], int, int) or is it the other way around?

Exceptions
IOException:

Doc from java.io.OutputStream.write.

if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

writeback to summary
public void write(String s) throws IOException

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).

Parameters
s:String

The string of non-special characters written to the OutputStream.

writeback to summary
protected abstract void write(char ch) throws IOException

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

Parameters
ch:char

The character written to the OutputStream.

writeSpecialback to summary
protected abstract void writeSpecial(int b) throws IOException

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

Parameters
b:int

The byte written to the OutputStream.