javax.swing.text.rtf
Class AbstractFilter

java.lang.Object
  extended byjava.io.OutputStream
      extended byjavax.swing.text.rtf.AbstractFilter
Direct Known Subclasses:
RTFParser

abstract class AbstractFilter
extends OutputStream

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
(package private) static boolean[] allSpecialsTable
          A specials table which indicates that all characters are special
(package private) static char[] latin1TranslationTable
          A translation table which does ISO Latin-1 (trivial)
(package private) static 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
AbstractFilter()
           
 
Method Summary
 void readFromReader(Reader in)
           
 void readFromStream(InputStream in)
          A convenience method that reads text from a FileInputStream and writes it to the receiver.
 void write(byte[] buf, int off, int len)
          Implements the buffer-at-a-time write method for greater efficiency.
protected abstract  void write(char ch)
          Subclasses must provide an implementation of this method which accepts a single (non-special) character.
 void write(int b)
          Implements the abstract method of OutputStream, of which this class is a subclass.
 void write(String 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 writeSpecial(int b)
          Subclasses must provide an implementation of this method which accepts a single special byte.
 
Methods inherited from class java.io.OutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

translationTable

protected char[] translationTable
A table mapping bytes to characters


specialsTable

protected boolean[] specialsTable
A table indicating which byte values should be interpreted as characters and which should be treated as formatting codes


latin1TranslationTable

static final char[] latin1TranslationTable
A translation table which does ISO Latin-1 (trivial)


noSpecialsTable

static final boolean[] noSpecialsTable
A specials table which indicates that no characters are special


allSpecialsTable

static final boolean[] allSpecialsTable
A specials table which indicates that all characters are special

Constructor Detail

AbstractFilter

public AbstractFilter()
Method Detail

readFromStream

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 - An InputStream providing text.
Throws:
IOException

readFromReader

public void readFromReader(Reader in)
                    throws IOException
Throws:
IOException

write

public void write(int b)
           throws IOException
Implements the abstract method of OutputStream, of which this class is a subclass.

Specified by:
write in class OutputStream
Parameters:
b - the byte.
Throws:
IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

write

public void write(byte[] buf,
                  int off,
                  int len)
           throws IOException
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?

Overrides:
write in class OutputStream
Parameters:
buf - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

write

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 - The string of non-special characters written to the OutputStream.
Throws:
IOException

write

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 - The character written to the OutputStream.
Throws:
IOException

writeSpecial

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 - The byte written to the OutputStream.
Throws:
IOException