Example usage for com.google.common.base Ascii truncate

List of usage examples for com.google.common.base Ascii truncate

Introduction

In this page you can find the example usage for com.google.common.base Ascii truncate.

Prototype

@Beta
public static String truncate(CharSequence seq, int maxLength, String truncationIndicator) 

Source Link

Document

Truncates the given character sequence to the given maximum length.

Usage

From source file:org.sfs.util.NullSafeAscii.java

public static String truncate(CharSequence seq, int maxLength, String truncationIndicator) {
    if (seq != null) {
        return Ascii.truncate(seq, maxLength, truncationIndicator);
    }/*from   w w  w .j  ava  2 s  .c  o m*/
    return null;
}

From source file:com.cisco.gerrit.plugins.slack.message.CommentAddedMessageGenerator.java

@Override
public String generate() {
    String message = "";

    String whatHappened = String.format("%s (%s) commented on %s", escape(event.author.name),
            escape(event.author.username), escape(event.change.url));
    String topic = "";
    if (event.change.topic != null && !event.change.topic.isEmpty()) {
        topic = String.format(" - (%s)", event.change.topic);
    }//from ww  w .j  a  v a 2  s  .  co m
    String attachmentTitle = String.format("%s - (%s)%s", escape(event.change.project),
            escape(event.change.branch), escape(topic));
    String attachmentValue = escape(Ascii.truncate(event.comment, 200, "..."));

    AttachmentMessage.Builder builder = new AttachmentMessage.Builder(config).withPretext(whatHappened)
            .withColor(AttachmentMessage.Builder.COLOR_GOOD).withAttachmentTitle(attachmentTitle)
            .withAttachmentValue(attachmentValue);

    try {
        message = builder.build().generate();
    } catch (Exception e) {
        LOGGER.error("Error generating message: " + e.getMessage(), e);
    }

    return message;
}

From source file:com.tinspx.util.io.ChannelSource.java

static String truncateBase16(byte[] bytes, int off, int len, int maxLength) {
    checkPositionIndexes(off, off + len, bytes.length);
    checkArgument(maxLength >= 0);/*from w w w .  ja  va 2 s  .c  o m*/
    return Ascii.truncate(BaseEncoding.base16().encode(bytes, off, Math.min(len, maxLength + 1)),
            Math.max(3, maxLength), "...");
}

From source file:com.google.devtools.build.lib.query2.SkyQueryEnvironment.java

@Override
public final QueryExpression transformParsedQuery(QueryExpression queryExpression) {
    QueryExpressionMapper mapper = getQueryExpressionMapper();
    QueryExpression transformedQueryExpression = queryExpression.getMapped(mapper);
    LOG.info(String.format("transformed query [%s] to [%s]",
            Ascii.truncate(queryExpression.toString(), MAX_QUERY_EXPRESSION_LOG_CHARS, "[truncated]"),
            Ascii.truncate(transformedQueryExpression.toString(), MAX_QUERY_EXPRESSION_LOG_CHARS,
                    "[truncated]")));
    return transformedQueryExpression;
}