Example usage for org.apache.commons.lang StringUtils left

List of usage examples for org.apache.commons.lang StringUtils left

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils left.

Prototype

public static String left(String str, int len) 

Source Link

Document

Gets the leftmost len characters of a String.

Usage

From source file:com.intel.cosbench.config.common.KVConfigParser.java

private static void addConfigEntry(String entry, Configuration config) {
    int pos = StringUtils.indexOf(entry, '=');
    if (pos < 0)
        logger.warn("cannot parse config entry {}", entry);

    String key = StringUtils.trim(StringUtils.left(entry, pos));
    String value = StringUtils.trim(StringUtils.right(entry, entry.length() - pos - 1));
    logger.debug("key=" + key + ";value=" + value);

    config.setProperty(key, value);//from   w  w w  .j av  a 2 s  .  c  o m
}

From source file:iddb.core.util.PasswordUtils.java

public static String hashPassword(String raw_password) {
    Random random = new Random(raw_password.length() + System.currentTimeMillis());
    String salt = StringUtils.left(HashUtils.getSHA1Hash(
            Float.toHexString(random.nextFloat()) + Float.toHexString(System.currentTimeMillis())), 5);
    String hashedPassword = HashUtils.getSHA1Hash(salt + raw_password);
    return salt + "$" + hashedPassword;
}

From source file:com.thoughtworks.go.domain.BuildOutputMatcher.java

public String match(CharSequence output) {
    Matcher matcher = COMPILED_PATTERN.matcher(output);
    String matchedString = null;/*from w ww . j  a  v a2  s.  c o  m*/
    while (matcher.find()) {
        matchedString = matcher.group(1);
    }
    return StringUtils.left(matchedString, 30);
}

From source file:com.evolveum.midpoint.repo.sql.helpers.mapper.EnumMapper.java

@Override
public SchemaEnum map(Enum input, MapperContext context) {
    String repoEnumClass = null;//  www  . j  ava  2s .  c o m
    try {
        String className = input.getClass().getSimpleName();
        Class clazz;
        if (input instanceof ExportType) {
            clazz = RExportType.class; // todo fix this brutal hack
        } else {
            className = StringUtils.left(className, className.length() - 4);
            repoEnumClass = "com.evolveum.midpoint.repo.sql.data.common.enums.R" + className;
            clazz = Class.forName(repoEnumClass);
        }

        if (!SchemaEnum.class.isAssignableFrom(clazz)) {
            throw new SystemException("Can't translate enum value " + input);
        }

        return RUtil.getRepoEnumValue(input, clazz);
    } catch (ClassNotFoundException ex) {
        throw new SystemException("Couldn't find class '" + repoEnumClass + "' for enum '" + input + "'", ex);
    }
}

From source file:at.porscheinformatik.common.spring.web.extended.util.ParboiledUtils.java

private static <T> String buildErrorMessag(ParsingResult<T> result, String resourceDescription) {
    StringBuilder builder = new StringBuilder();
    builder.append("Template " + resourceDescription + " contains errors: \n");
    for (ParseError error : result.parseErrors) {
        int start = error.getStartIndex();
        int end = error.getEndIndex();

        if (start - 10 > 0) {
            start -= 10;//from  w  w  w  .jav a  2s .  c  o  m
        } else {
            start = 0;
        }

        builder.append(error.getInputBuffer().extract(start, end)).append(" --> ");

        if (error.getErrorMessage() != null) {
            builder.append(error.getErrorMessage());
        } else {
            builder.append(error.toString());
        }

        builder.append("\n");

        builder.append(StringUtils.leftPad("^", error.getStartIndex() - start - 1));

        if (error.getEndIndex() > error.getStartIndex()) {
            builder.append(StringUtils.left("^", error.getEndIndex() - error.getStartIndex() - 1));
        }
    }

    return builder.toString();
}

From source file:com.antsdb.saltedfish.sql.vdm.FuncLeft.java

@Override
public long eval(VdmContext ctx, Heap heap, Parameters params, long pRecord) {
    long pString = this.parameters.get(0).eval(ctx, heap, params, pRecord);
    if (pString == 0) {
        return 0;
    }//from w  ww . jav a 2  s  .co m
    long pLength = this.parameters.get(1).eval(ctx, heap, params, pRecord);
    if (pLength == 0) {
        return 0;
    }
    String str = (String) FishObject.get(heap, AutoCaster.toString(heap, pString));
    Long length = (Long) FishObject.get(heap, AutoCaster.toNumber(heap, pLength));
    String result = StringUtils.left(str, (int) (long) length);
    return Unicode16.allocSet(heap, result);
}

From source file:hudson.plugins.blazemeter.BlazemeterCredentialImpl.java

private String calcLegacyId(String jobApiKey) {
    return StringUtils.left(jobApiKey, 4) + "..." + StringUtils.right(jobApiKey, 4);
}

From source file:ai.grakn.graql.VarName.java

/**
 * Get a shorter representation of the variable (with prefixed "$")
 */
public String shortName() {
    return "$" + StringUtils.left(value, 3);
}

From source file:de.innovationgate.webgate.api.jdbc.PortletRegistryImplV4.java

public static String buildNamespacePrefix(String dbkey) {

    dbkey = dbkey.toLowerCase();/*from  w w  w.j a  v a2  s  . c o m*/
    String prefix = StringUtils.left(dbkey, 1) + StringUtils.right(dbkey, 2);
    if (prefix.length() < 3) {
        prefix += StringUtils.repeat("x", 3 - prefix.length());
    }

    // Escape non alphanumeric characters as x
    char[] chars = prefix.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (!Character.isLetterOrDigit(chars[i])) {
            chars[i] = 'x';
        }
    }

    return new String(chars);

}