| Overview | Package | Class | Tree | Deprecated | Index | Help | |||
| PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||
java.lang.Object
|
+--java.io.Writer
|
+--ncsa.horizon.util.MessageBuffer
The limit of the buffer is set when the buffer is constructed. This limit can be set either as a number of characters/bytes (default) or a number of lines (as delimited by \n characters). Clients write messages to this writer which are appended to the end of the buffer. If the size of the buffer plus the size of the new message (either in number of lines or characters) exceeds the buffer limit, text at the beginning of the buffer will be trimmed off.
How much text gets automatically trimmed depends on the property accessed via is/setTrimmedByLines(). If isTrimmedByLines() returns true (which is the default), whole lines will be trimmed from the beginning of the buffer as necessary to keep the buffer size below its limit.
This class also supports listeners who are notified whenever the buffer is flushed or cleared. (Flushing does not cause any data to be thrown away.) This allows such clients as gui components (like a TextArea) to update their displays, especially when new messages are sent. In this case, it is convenient to wrap the buffer with a PrintWriter or MultiPrintWriter with auto-flushing; this will cause listeners to be alerted automatically after every complete line (ending in a newline character).
| Inner Class Summary | |
| MessageBuffer.Enum
|
|
| static | MessageBuffer.Listener
an interface for objects that wish to listen for changes to this buffer |
| Field Summary | |
| int | capacity
the maximum capacity. |
| boolean | capIsByLines
true if capacity refers to a number of lines |
| boolean | trimByLines
true if the buffer should be automatically trimmed at line boundaries |
| Fields inherited from class java.io.Writer | |
| lock | |
| Constructor Summary | |
| MessageBuffer(int maxcap,
boolean byLines,
java.lang.String str)
create a MessageBuffer with a given maximum capacity and given contents |
|
| MessageBuffer(int maxcap,
boolean byLines)
create a MessageBuffer with a given maximum capacity |
|
| MessageBuffer(int maxchar)
create a MessageBuffer with a given maximum character capacity |
|
| MessageBuffer()
create a MessageBuffer with unlimited capacity |
|
| Method Summary | |
| void | addListener(MessageBuffer.Listener l)
add a listener of this buffer |
| boolean | capacityIsByLines()
return true if the capacity of the buffer has been set by the number of lines |
| void | clear()
clear contents of buffer |
| java.lang.Object | clone()
|
| void | close()
close this writer. |
| static int | countLines(char[] str,
int offset,
int count)
count the number of lines in a given string |
| void | flush()
flush this writer. |
| int | getLineCount()
return the number of lines in the buffer |
| boolean | isTrimmedByLines()
return true if this buffer will be trimmed by whole lines. |
| int | length()
return length of contents |
| MessageBuffer.Enum | lines()
get an enumerator of the lines in the buffer |
| static void | main(java.lang.String[] argv)
|
| int | maxCapacity()
return the maximum this buffer can hold. |
| void | removeListener(MessageBuffer.Listener l)
remove a listener of this buffer |
| void | setTrimmedByLines(boolean yes)
set whether this buffer will be trimmed by whole lines. |
| java.lang.String | toString()
convert contents to a String |
| void | trimChars(int nchars)
trim characters from the beginning of the buffer |
| void | trimLines(int nlines)
trim whole lines from the beginning of the buffer |
| void | write(char[] str,
int offset,
int count)
append a message to the buffer |
| Methods inherited from class java.io.Writer | |
| close, flush, write, write, write, write, write | |
| Methods inherited from class java.lang.Object | |
| clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait | |
| Field Detail |
protected boolean trimByLines
protected int capacity
protected boolean capIsByLines
| Constructor Detail |
public MessageBuffer(int maxcap,
boolean byLines,
java.lang.String str)
maxcap
- the maximum size of the buffer; there is no maximum
limit if maxcap <= 0
byLines
- if true, the maxcap refers to the number of lines;
otherwise, it is the number of characters.
str
- string to initialize buffer with (ignored if null)
public MessageBuffer(int maxcap,
boolean byLines)
maxcap
- the maximum size of the buffer; there is no maximum
limit if maxcap <= 0
byLines
- if true, the maxcap refers to the number of lines;
otherwise, it is the number of characters.public MessageBuffer(int maxchar)
maxchar
- the maximum number of characters in the buffer;
there is no maximum limit if maxcap <= 0public MessageBuffer()
| Method Detail |
public boolean isTrimmedByLines()
public void setTrimmedByLines(boolean yes)
public void write(char[] str,
int offset,
int count)
public void trimChars(int nchars)
nchars
- the number of characters to trim from beginning
of buffer.public void trimLines(int nlines)
public static int countLines(char[] str,
int offset,
int count)
public boolean capacityIsByLines()
public int maxCapacity()
public java.lang.String toString()
public int length()
public int getLineCount()
public void clear()
public MessageBuffer.Enum lines()
public void flush()
public void close()
public void addListener(MessageBuffer.Listener l)
public void removeListener(MessageBuffer.Listener l)
public java.lang.Object clone()
public static void main(java.lang.String[] argv)
| Overview | Package | Class | Tree | Deprecated | Index | Help | |||
| PREV CLASS | NEXT CLASS | FRAMES | NO FRAMES | ||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||