Example usage for org.apache.commons.lang3 StringUtils leftPad

List of usage examples for org.apache.commons.lang3 StringUtils leftPad

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils leftPad.

Prototype

public static String leftPad(final String str, final int size, String padStr) 

Source Link

Document

Left pad a String with a specified String.

Pad to a size of size .

 StringUtils.leftPad(null, *, *)      = null StringUtils.leftPad("", 3, "z")      = "zzz" StringUtils.leftPad("bat", 3, "yz")  = "bat" StringUtils.leftPad("bat", 5, "yz")  = "yzbat" StringUtils.leftPad("bat", 8, "yz")  = "yzyzybat" StringUtils.leftPad("bat", 1, "yz")  = "bat" StringUtils.leftPad("bat", -1, "yz") = "bat" StringUtils.leftPad("bat", 5, null)  = "  bat" StringUtils.leftPad("bat", 5, "")    = "  bat" 

Usage

From source file:wsattacker.plugin.dos.dosExtension.util.UtilHashDoS.java

public static String generateUntampered(CollisionInterface collisionInterface, int numberOfAttributes,
        boolean useNamespace) {

    String attributeName = UtilHashDoS.determineUntamperedAttributeName(collisionInterface, numberOfAttributes,
            useNamespace);//from w w w .  ja va  2s.c om

    int size = String.valueOf(numberOfAttributes).length();

    String prefix = "";
    if (useNamespace == true) {
        prefix = "xmlns:";
    }

    // create final SOAP message with payload
    StringBuilder sb = new StringBuilder("");
    for (int i = 0; i < numberOfAttributes; i++) {
        sb.append(" ").append(prefix).append(attributeName);
        sb.append(StringUtils.leftPad(String.valueOf(i), size, '0'));
        sb.append("=\"").append(i).append("\"");
    }

    return sb.toString();
}