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

The following are Jave code examples for showing how to use substring() 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: weixin_api   File: HttpUtil.java   View Source Code Vote up 6 votes
/**
 * 从响应消息的Content-Disposition头中获得文件名。
 * 
 * @param headers
 * @return 如果不是文件则返回null
 */
private static String getResponseFileName(Header[] headers) {
	String filename = null;
	if (headers == null) {
		return null;
	}
	for (Header header : headers) {
		if (StringUtils.equalsIgnoreCase(header.getName(), "Content-Disposition")) {
			String value = header.getValue();
			String key = "filename=";
			int keyLength = key.length();
			int position = StringUtils.indexOfIgnoreCase(header.getValue(), key);
			if (position > -1) {
				filename = StringUtils.substring(value, position + keyLength);
			}
			break;
		}
	}
	return filename;
}
 
Example 2
Project: nifi-registry   File: CertificateUtils.java   View Source Code Vote up 6 votes
/**
 * Extracts the username from the specified DN. If the username cannot be extracted because the CN is in an unrecognized format, the entire CN is returned. If the CN cannot be extracted because
 * the DN is in an unrecognized format, the entire DN is returned.
 *
 * @param dn the dn to extract the username from
 * @return the exatracted username
 */
public static String extractUsername(String dn) {
    String username = dn;

    // ensure the dn is specified
    if (StringUtils.isNotBlank(dn)) {
        // determine the separate
        final String separator = StringUtils.indexOfIgnoreCase(dn, "/cn=") > 0 ? "/" : ",";

        // attempt to locate the cd
        final String cnPattern = "cn=";
        final int cnIndex = StringUtils.indexOfIgnoreCase(dn, cnPattern);
        if (cnIndex >= 0) {
            int separatorIndex = StringUtils.indexOf(dn, separator, cnIndex);
            if (separatorIndex > 0) {
                username = StringUtils.substring(dn, cnIndex + cnPattern.length(), separatorIndex);
            } else {
                username = StringUtils.substring(dn, cnIndex + cnPattern.length());
            }
        }
    }

    return username;
}
 
Example 3
Project: SpringBootStudy   File: WebMvcConfig.java   View Source Code Vote up 6 votes
/**
 * 一个简单的签名认证,规则:
 * 1. 将请求参数按ascii码排序
 * 2. 拼接为a=value&b=value...这样的字符串(不包含sign)
 * 3. 混合密钥(secret)进行md5获得签名,与请求的签名进行比较
 */
private boolean validateSign(HttpServletRequest request) {
    String requestSign = request.getParameter("sign");//获得请求签名,如sign=19e907700db7ad91318424a97c54ed57
    if (StringUtils.isEmpty(requestSign)) {
        return false;
    }
    List<String> keys = new ArrayList<String>(request.getParameterMap().keySet());
    keys.remove("sign");        //排除sign参数
    Collections.sort(keys);     //排序

    StringBuilder sb = new StringBuilder();
    for (String key : keys) {
        sb.append(key).append("=").append(request.getParameter(key)).append("&");//拼接字符串
    }
    String linkString = sb.toString();
    linkString = StringUtils.substring(linkString, 0, linkString.length() - 1);//去除最后一个'&'

    String secret = "Potato";   //密钥,自己修改
    String sign = DigestUtils.md5Hex(linkString + secret);//混合密钥md5

    return StringUtils.equals(sign, requestSign);//比较
}
 
Example 4
Project: cyberduck   File: PathRelativizer.java   View Source Code Vote up 6 votes
public static String relativize(String root, final String path) {
    if(StringUtils.isBlank(root)) {
        return path;
    }
    if(!StringUtils.equals(root, String.valueOf(Path.DELIMITER))) {
        root = root + String.valueOf(Path.DELIMITER);
    }
    if(StringUtils.contains(path, root)) {
        return StringUtils.substring(path, path.indexOf(root) + root.length());
    }
    return path;
}
 
Example 5
Project: SpringBootStudy   File: WebMvcConfig.java   View Source Code Vote up 6 votes
/**
 * 一个简单的签名认证,规则:
 * 1. 将请求参数按ascii码排序
 * 2. 拼接为a=value&b=value...这样的字符串(不包含sign)
 * 3. 混合密钥(secret)进行md5获得签名,与请求的签名进行比较
 */
private boolean validateSign(HttpServletRequest request) {
    String requestSign = request.getParameter("sign");//获得请求签名,如sign=19e907700db7ad91318424a97c54ed57
    if (StringUtils.isEmpty(requestSign)) {
        return false;
    }
    List<String> keys = new ArrayList<String>(request.getParameterMap().keySet());
    keys.remove("sign");//排除sign参数
    Collections.sort(keys);//排序

    StringBuilder sb = new StringBuilder();
    for (String key : keys) {
        sb.append(key).append("=").append(request.getParameter(key)).append("&");//拼接字符串
    }
    String linkString = sb.toString();
    linkString = StringUtils.substring(linkString, 0, linkString.length() - 1);//去除最后一个'&'

    String secret = "Potato";//密钥,自己修改
    String sign = DigestUtils.md5Hex(linkString + secret);//混合密钥md5

    return StringUtils.equals(sign, requestSign);//比较
}
 
Example 6
Project: pingguopai   File: WebMvcConfigurer.java   View Source Code Vote up 6 votes
/**
 * 一个简单的签名认证,规则:
 * 1. 将请求参数按ascii码排序
 * 2. 拼接为a=value&b=value...这样的字符串(不包含sign)
 * 3. 混合密钥(secret)进行md5获得签名,与请求的签名进行比较
 */
private boolean validateSign(HttpServletRequest request) {
    String requestSign = request.getParameter("sign");//获得请求签名,如sign=19e907700db7ad91318424a97c54ed57
    if (StringUtils.isEmpty(requestSign)) {
        return false;
    }
    List<String> keys = new ArrayList<String>(request.getParameterMap().keySet());
    keys.remove("sign");//排除sign参数
    Collections.sort(keys);//排序

    StringBuilder sb = new StringBuilder();
    for (String key : keys) {
        sb.append(key).append("=").append(request.getParameter(key)).append("&");//拼接字符串
    }
    String linkString = sb.toString();
    linkString = StringUtils.substring(linkString, 0, linkString.length() - 1);//去除最后一个'&'

    String secret = "Potato";//密钥,自己修改
    String sign = DigestUtils.md5Hex(linkString + secret);//混合密钥md5

    return StringUtils.equals(sign, requestSign);//比较
}
 
Example 7
Project: eds   File: RequestIdManager.java   View Source Code Vote up 5 votes
public RequestIdManager(String serviceId) {
  if (serviceId == null) {
    serviceIdTag = "9999";
  }
  if (serviceId.length() > SERVICE_ID_TAG_LENGTH) {
    serviceIdTag = StringUtils
        .substring(serviceId, serviceId.length() - SERVICE_ID_TAG_LENGTH, serviceId.length() - 1);
  } else {
    serviceIdTag = StringUtils.leftPad(serviceId, SERVICE_ID_TAG_LENGTH, '0');
  }
}
 
Example 8
Project: Thrush   File: StationNameUtil.java   View Source Code Vote up 5 votes
public static void parse(String js) {
    if (StringUtils.isBlank(js)) {
        return;
    }

    String str = StringUtils.substring(js, js.indexOf("'") + 1, js.lastIndexOf("'"));
    String[] arr = str.split("@");
    Map<String, List<Station>> result = Arrays.stream(arr).filter(s -> StringUtils.isNotBlank(s)).map(s -> {
        String[] stations = s.split("\\|");
        return new Station(stations[0], stations[1], stations[2], stations[3]);
    }).collect(Collectors.groupingBy(station -> station.getName()));

    stationMaps = result;
}
 
Example 9
Project: simm-lib   File: WeightedSensitivityUtils.java   View Source Code Vote up 5 votes
public static String determineQualifier(RiskClass riskClass, Sensitivity sensitivity) {
  String qualifier = sensitivity.getQualifier();

  if (RiskClass.FX.equals(riskClass)) {
    String ccy1 = StringUtils.substring(qualifier, 0, 3);
    String ccy2 = StringUtils.substring(qualifier, 3, 6);
    qualifier = Arrays.asList(ccy1, ccy2).stream().sorted().reduce((s1, s2) -> {
      return s1 + s2;
    }).get();
  }
  return qualifier;
}
 
Example 10
Project: cyberduck   File: AbstractSymlinkResolver.java   View Source Code Vote up 5 votes
@Override
public String relativize(final String base, final String name) {
    final String parent = PathNormalizer.parent(base, Path.DELIMITER);
    if(name.startsWith(parent)) {
        return StringUtils.substring(name, parent.length() + 1);
    }
    else {
        return String.format("..%s%s", Path.DELIMITER, this.relativize(parent, name));
    }
}
 
Example 11
Project: strqlbuilder   File: Aliases.java   View Source Code Vote up 5 votes
private String unquote(String str) {
if (isQuoted(str)) {
    return StringUtils.substring(str, 1, -1);
} else {
    return str;
}
   }
 
Example 12
Project: spring2ts   File: ServicePath.java   View Source Code Vote up 5 votes
private String extractVariableName(String path, int start, int end, Set<String> variables) {
    String substring = StringUtils.substring(path, start, end);
    String stripped = StringUtils.strip(substring, "{}");
    String variable = StringUtils.substringBefore(stripped, ":");
    variables.add(variable);
    return String.format("${%s}", variable);
}
 
Example 13
Project: HL7Receiver   File: AddressConverter.java   View Source Code Vote up 5 votes
public static String formatPostcode(String postcode) {
    String formattedPostcode = StringUtils.deleteWhitespace(postcode.toUpperCase());

    if ((formattedPostcode.length() >= 5) && (formattedPostcode.length() <= 7)) {
        formattedPostcode =
                StringUtils.substring(formattedPostcode, 0, formattedPostcode.length() - 3)
                        + " "
                        + StringUtils.substring(formattedPostcode, formattedPostcode.length() - 3);
    }

    return formattedPostcode;
}
 
Example 14
Project: theskeleton   File: PostServiceImpl.java   View Source Code Vote up 4 votes
private String slugifyTitle(String title) {
	return StringUtils.substring(slugify.slugify(title), 0, 20);
}
 
Example 15
Project: shepher   File: ReviewUtil.java   View Source Code Vote up 4 votes
public static String generateSummary(String content) {
    String summary = StringEscapeUtils.escapeXml(content);
    summary = StringUtils.substring(summary, 0, 50);
    return summary;
}
 
Example 16
Project: strqlbuilder   File: Aliases.java   View Source Code Vote up 4 votes
public String fixAliasForBean(String alias) {
if (alias.startsWith("\"") && alias.endsWith("\"")) {
    return StringUtils.substring(alias, 1, -1);
}
return alias;
   }
 
Example 17
Project: OperatieBRP   File: BrpPostfix.java   View Source Code Vote up 4 votes
static String appendTo(final String naam, Number id) {
    final String idwaarde = id.toString();
    return StringUtils.substring(naam, 0, MAX_LENGTE_PREFIX - idwaarde.length()) + "BRP" + idwaarde;

}
 
Example 18
Project: Android_watch_magpie   File: LogicTupleEvent.java   View Source Code Vote up 4 votes
private String getSubstring(String start, String end) {
    int first = StringUtils.indexOf(logicRepresentation, start);
    int second = StringUtils.indexOf(logicRepresentation, end);
    return StringUtils.substring(logicRepresentation, first + 1, second);
}
 
Example 19
Project: vscrawler   File: SubString.java   View Source Code Vote up 4 votes
@Override
protected String handle(String str, int start, int end) {
    return StringUtils.substring(str, start, end);
}
 
Example 20
Project: spring-boot-start-current   File: StringProUtils.java   View Source Code Vote up 2 votes
/**
 * <p>
 * 前n个首字母大写,之后字符大小写的不变
 * </p>
 *
 * @param rawString 需要处理的字符串
 * @param index     多少个字符(从左至右)
 * @return
 */
public static String prefixToUpperCase ( String rawString , int index ) {
    String beforeChar = StringUtils.substring( rawString , 0 , index ).toUpperCase();
    String afterChar  = StringUtils.substring( rawString , index , rawString.length() );
    return beforeChar + afterChar;
}