Java Code Examples for org.apache.commons.lang3.StringUtils.left()

The following are Jave code examples for showing how to use left() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: mafia   File: HttpUtil.java   View Source Code Vote up 6 votes
private static String httpRequest(String url, Object data, String method, int timeoutMilliseconds/*毫秒*/, int retryTimes) {
    Preconditions.checkArgument(retryTimes <= 10 && retryTimes >= 0, "retryTimes should between 0(include) and 10(include)");
    method = StringUtils.upperCase(method);
    Preconditions.checkArgument(HttpMethod.resolve(method) != null, "http request method error");
    try {
        HttpRequest request = getHttpRequest(url, data, method);
        long start = System.currentTimeMillis();
        String uuid = StringUtils.left(UUID.randomUUID().toString(), 13);
        logger.info("UUID:{}, Request URL:{} , method:{}, Request data:{}", uuid, url, method, JsonUtil.writeValueQuite(data));
        request.setNumberOfRetries(retryTimes);
        request.setConnectTimeout(timeoutMilliseconds);
        request.setLoggingEnabled(LOGGING_ENABLED);
        HttpResponse response = request.execute();
        response.setLoggingEnabled(LOGGING_ENABLED);
        InputStream in = new BufferedInputStream(response.getContent());
        String res = StreamUtils.copyToString(in, Charsets.UTF_8);
        logger.info("UUID:{}, Request cost [{}ms], Response data:{}", uuid, (System.currentTimeMillis() - start), res);
        return res;
    } catch (IOException e) {
        logger.warn("Http request error", e);
    }
    return StringUtils.EMPTY;
}
 
Example 2
Project: uroborosql   File: StringFunction.java   View Source Code Vote up 2 votes
/**
 * 文字列の先頭から指定した文字数の文字列を取得する
 *
 * <pre>
 * StringUtils.left(null, *)    = null
 * StringUtils.left(*, -ve)     = ""
 * StringUtils.left("", *)      = ""
 * StringUtils.left("abc", 0)   = ""
 * StringUtils.left("abc", 2)   = "ab"
 * StringUtils.left("abc", 4)   = "abc"
 * </pre>
 *
 * @param str 対象文字列
 * @param len 文字数
 * @return 文字列の先頭から文字数で指定した長さの文字列
 */
public String left(final String str, final int len) {
	return StringUtils.left(str, len);
}