java.lang.Object
com.dua3.utility.logging.LogBuffer
- All Implemented Interfaces:
LogEntryHandler,Externalizable,Serializable
A log buffer class intended to provide a buffer for log messages to display in GUI applications.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceInterface for Listeners on changes of aLogBufferinstance's contents. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd LogBufferListener.voidappendTo(Appendable app) Appends all LogEntries in this LogBuffer to the specified Appendable.voidclear()Clear the LogBuffer.get(int i) Get the LogEntry at the specified index in the LogBuffer.voidhandleEntry(LogEntry entry) Handles a log entry.voidvoidRemove LogBufferListener.intsize()Returns the size of the LogBuffer.subList(int fromIndex, int toIndex) Returns a view of the portion of this LogBuffer between the specifiedfromIndex, inclusive, andtoIndex, exclusive.LogEntry[]toArray()Converts the LogBuffer into an array of LogEntry objects.void
-
Field Details
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYThe default capacity.- See Also:
-
-
Constructor Details
-
LogBuffer
public LogBuffer()Construct a new LogBuffer instance with default capacity. -
LogBuffer
public LogBuffer(int capacity) Construct a new LogBuffer instance.- Parameters:
capacity- the initial capacity
-
-
Method Details
-
writeExternal
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
addLogBufferListener
Add LogBufferListener.- Parameters:
listener- the listener to add
-
removeLogBufferListener
Remove LogBufferListener.- Parameters:
listener- the listener to remove
-
handleEntry
Description copied from interface:LogEntryHandlerHandles a log entry.- Specified by:
handleEntryin interfaceLogEntryHandler- Parameters:
entry- the log entry to be handled
-
clear
public void clear()Clear the LogBuffer. Synchronized method that clears the buffer and notifies all registered LogBufferListeners to clear their logs as well. -
toArray
Converts the LogBuffer into an array of LogEntry objects.- Returns:
- an array of LogEntry objects representing the contents of the LogBuffer
-
get
Get the LogEntry at the specified index in the LogBuffer.- Parameters:
i- the index of the LogEntry to retrieve- Returns:
- the LogEntry at the specified index
-
size
public int size()Returns the size of the LogBuffer.- Returns:
- the number of LogEntries in the LogBuffer.
-
subList
Returns a view of the portion of this LogBuffer between the specifiedfromIndex, inclusive, andtoIndex, exclusive.- Parameters:
fromIndex- the index of the first LogEntry to be included in the returned subList.toIndex- the index after the last LogEntry to be included in the returned subList.- Returns:
- a view of the specified range within this LogBuffer.
- Throws:
IndexOutOfBoundsException- iffromIndexortoIndexis out of range (fromIndex < 0 || toIndex > size() || fromIndex > toIndex).
-
appendTo
Appends all LogEntries in this LogBuffer to the specified Appendable.- Parameters:
app- the Appendable to which the LogEntries will be appended- Throws:
IOException- if an I/O error occurs while appending the LogEntries
-