Package org.apache.hadoop.yarn.util
Class BoundedAppender
java.lang.Object
org.apache.hadoop.yarn.util.BoundedAppender
A
CharSequence appender that considers its limit as upper
bound.
When limit would be reached on append, past messages will be
truncated from head, and a header telling the user about truncation will be
prepended, with ellipses in between header and messages.
Note that header and ellipses are not counted against limit.
An example:
// At the beginning it's an empty string
final Appendable shortAppender = new BoundedAppender(80);
// The whole message fits into limit
shortAppender.append(
"message1 this is a very long message but fitting into limit\n");
// The first message is truncated, the second not
shortAppender.append("message2 this is shorter than the previous one\n");
// The first message is deleted, the second truncated, the third
// preserved
shortAppender.append("message3 this is even shorter message, maybe.\n");
// The first two are deleted, the third one truncated, the last preserved
shortAppender.append("message4 the shortest one, yet the greatest :)");
// Current contents are like this:
// Diagnostic messages truncated, showing last 80 chars out of 199:
// ...s is even shorter message, maybe.
// message4 the shortest one, yet the greatest :)
Note that null values are appended
just like in original
implementation.
Note that this class is not thread safe.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionappend(CharSequence csq) Append aCharSequenceconsideringlimit, truncating from the head ofcsqormessageswhen necessary.intgetLimit()intlength()Get current length of messages considering truncates without header and ellipses.toString()Get a string representation of the actual contents, displaying also a header and ellipses when there was a truncate.
-
Field Details
-
TRUNCATED_MESSAGES_TEMPLATE
- See Also:
-
-
Constructor Details
-
BoundedAppender
public BoundedAppender(int limit)
-
-
Method Details
-
append
Append aCharSequenceconsideringlimit, truncating from the head ofcsqormessageswhen necessary.- Parameters:
csq- theCharSequenceto append- Returns:
- this
-
length
public int length()Get current length of messages considering truncates without header and ellipses.- Returns:
- current length
-
getLimit
public int getLimit() -
toString
Get a string representation of the actual contents, displaying also a header and ellipses when there was a truncate.
-