Package org.machanism.machai.ai.tools
Class LimitedStringBuilder
java.lang.Object
org.machanism.machai.ai.tools.LimitedStringBuilder
A
StringBuilder-like helper that retains only the last maxSize characters.
This utility is typically used when capturing potentially unbounded output (for example, process stdout/stderr) while keeping a deterministic upper bound on memory usage.
-
Constructor Summary
ConstructorsConstructorDescriptionLimitedStringBuilder(int maxSize) Creates a builder that keeps at mostmaxSizecharacters. -
Method Summary
-
Constructor Details
-
LimitedStringBuilder
public LimitedStringBuilder(int maxSize) Creates a builder that keeps at mostmaxSizecharacters.- Parameters:
maxSize- maximum number of characters to retain; must be positive- Throws:
IllegalArgumentException- ifmaxSizeis not positive
-
-
Method Details
-
append
Appends text to this builder, trimming any excess characters from the start to stay within the configured maximum size.- Parameters:
text- text to append; ignored ifnull- Returns:
- this instance for fluent chaining
-
getLastText
Returns the retained content.If truncation occurred, a prefix is added to indicate that earlier content was discarded.
- Returns:
- retained text (possibly with a truncation prefix)
-
length
public int length()Returns the number of characters currently retained.- Returns:
- retained length
-
clear
public void clear()Clears the retained content.
-