Package org.machanism.machai.gw.tools
Class LimitedStringBuilder
java.lang.Object
org.machanism.machai.gw.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, String commandId, File projectDir) Creates a builder that keeps at mostmaxSizecharacters. -
Method Summary
Modifier and TypeMethodDescriptionAppends text to this builder, trimming any excess characters from the start to stay within the configured maximum size.voidclear()Clears the retained content.static PathgetCommandLogPath(File projectDir, String commandId) Returns the retained content.intlength()Returns the number of characters currently retained.
-
Constructor Details
-
LimitedStringBuilder
Creates a builder that keeps at mostmaxSizecharacters.- Parameters:
maxSize- maximum number of characters to retain; must be positivecommandId-- 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. Also appends the text to a log file at: {projectDir}/.machai/command-log/{commandId}.log- Parameters:
text- text to append; ignored ifnullprojectDir- the project directory (used for log file path)- Returns:
- this instance for fluent chaining
-
getCommandLogPath
-
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.
-