@InterfaceAudience.Public @InterfaceStability.Unstable public class BoundedAppender extends Object
CharSequenceappender that considers its
limitas upper bound.
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
// 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
just like in
Note that this class is not thread safe.
|Modifier and Type||Field and Description|
|Constructor and Description|
|Modifier and Type||Method and Description|
Get current length of messages considering truncates without header and ellipses.
Get a string representation of the actual contents, displaying also a header and ellipses when there was a truncate.
public static final String TRUNCATED_MESSAGES_TEMPLATE
public BoundedAppender append(CharSequence csq)
limit, truncating from the head of
public int length()
public int getLimit()
Copyright © 2018 Apache Software Foundation. All rights reserved.