Class LogBuffer

java.lang.Object
com.dua3.utility.logging.LogBuffer
All Implemented Interfaces:
LogEntryHandler, Externalizable, Serializable

public class LogBuffer extends Object implements LogEntryHandler, Externalizable
A log buffer class intended to provide a buffer for log messages to display in GUI applications.
See Also:
  • Field Details

    • DEFAULT_CAPACITY

      public static final int DEFAULT_CAPACITY
      The 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

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • addLogBufferListener

      public void addLogBufferListener(LogBuffer.LogBufferListener listener)
      Add LogBufferListener.
      Parameters:
      listener - the listener to add
    • removeLogBufferListener

      public void removeLogBufferListener(LogBuffer.LogBufferListener listener)
      Remove LogBufferListener.
      Parameters:
      listener - the listener to remove
    • handleEntry

      public void handleEntry(LogEntry entry)
      Description copied from interface: LogEntryHandler
      Handles a log entry.
      Specified by:
      handleEntry in interface LogEntryHandler
      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

      public LogEntry[] toArray()
      Converts the LogBuffer into an array of LogEntry objects.
      Returns:
      an array of LogEntry objects representing the contents of the LogBuffer
    • get

      public LogEntry get(int i)
      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

      public List<LogEntry> subList(int fromIndex, int toIndex)
      Returns a view of the portion of this LogBuffer between the specified fromIndex, inclusive, and toIndex, 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 - if fromIndex or toIndex is out of range (fromIndex < 0 || toIndex > size() || fromIndex > toIndex).
    • appendTo

      public void appendTo(Appendable app) throws IOException
      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