public static String getHost(String url) { String host = url; int i = StringUtils.ordinalIndexOf(url, "/", 3); if (i > 0) { host = StringUtils.substring(url, 0, i); } return host; }
@Override public String toString() { if (StringUtils.isNotBlank(content)&&content.length()>100){ //方便查看截断下 this.content = StringUtils.substring(content,0,100)+"..."; } return ToStringBuilder.reflectionToString(this); } }
public void updateLabel(Map<CaseInsensitiveString, String> namedRevisions, int pipelineCounter) { this.label = interpolateLabel(namedRevisions, pipelineCounter); this.label = StringUtils.substring(label, 0, 255); }
/** * 一个简单的签名认证,规则: * 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);//比较 }
/** * Create a string with a fixed size. Can be useful for testing * validator based on length string for example * * @param numberOfLetters size of the expected String * @return a string with a fixed size */ public String fixedString(int numberOfLetters) { StringBuilder builder = new StringBuilder(); while (builder.length() < numberOfLetters) { builder.append(sentence()); } return StringUtils.substring(builder.toString(), 0, numberOfLetters); }
private String getTypeAdminSectionMismatchUrl(TypedEntity typedEntity, String ceilingEntity, String uri, String sectionKey) { int lastDotIndex = StringUtils.lastIndexOf(ceilingEntity, "."); String ceilingEntityType = StringUtils.substring(ceilingEntity, lastDotIndex + 1).toLowerCase(); String entityType = typedEntity.getType().getType().toLowerCase(); if (StringUtils.equals(entityType, "standard") || StringUtils.equals(ceilingEntityType, entityType)) { return StringUtils.replace(uri, sectionKey, "/" + ceilingEntityType); } return StringUtils.replace(uri, sectionKey, "/" + ceilingEntityType + ":" + entityType); }
private String toGeneralKey(String key) { String prefix = getPrivateKeyPrefix(); if (!StringUtils.startsWith(key, prefix)) { ErrorState.ILLEGAL_KEY_ACCESS.newBizException(); } return StringUtils.substring(key, prefix.length()); } }
private boolean typeMatchesAdminSection(TypedEntity typedEntity, String sectionKey) { String urlType = StringUtils.substring(sectionKey, sectionKey.indexOf(":") + 1); if(!StringUtils.equalsIgnoreCase(typedEntity.getType().getType(), urlType)) { return false; } return true; }
/** * Parse {@link org.joda.time.DateTime} from {@link org.apache.hadoop.fs.Path} using datetime pattern. */ @Override public TimestampedDatasetVersion getDatasetVersion(Path pathRelativeToDatasetRoot, FileStatus versionFileStatus) { String dateTimeString = null; try { // pathRelativeToDatasetRoot can be daily/2016/03/02 or 2016/03/02. In either case we need to pick 2016/03/02 as version dateTimeString = StringUtils.substring(pathRelativeToDatasetRoot.toString(), pathRelativeToDatasetRoot.toString().length() - this.datePartitionPattern.length()); return new FileStatusTimestampedDatasetVersion(this.formatter.parseDateTime(dateTimeString), versionFileStatus); } catch (IllegalArgumentException exception) { LOGGER.warn(String.format( "Candidate dataset version with pathRelativeToDatasetRoot: %s has inferred dataTimeString:%s. " + "It does not match expected datetime pattern %s. Ignoring.", pathRelativeToDatasetRoot, dateTimeString, this.datePartitionPattern)); return null; } } }
public static String getDomain(String url) { String domain = removeProtocol(url); int i = StringUtils.indexOf(domain, "/", 1); if (i > 0) { domain = StringUtils.substring(domain, 0, i); } return removePort(domain); }
/** * 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; }
@Override public String evaluate(FunctionArgs args, EvaluationContext context) { final String value = valueParam.required(args, context); final Long startValue = startParam.required(args, context); if (value == null || startValue == null) { return null; } final int start = Ints.saturatedCast(startValue); final int end = Ints.saturatedCast(endParam.optional(args, context).orElse((long) value.length())); return StringUtils.substring(value, start, end); }
@Test public void testSubstring_StringIntInt() { assertNull(StringUtils.substring(null, 0, 0)); assertNull(StringUtils.substring(null, 1, 2)); assertEquals("", StringUtils.substring("", 0, 0)); assertEquals("", StringUtils.substring("", 1, 2)); assertEquals("", StringUtils.substring("", -2, -1)); assertEquals("", StringUtils.substring(SENTENCE, 8, 6)); assertEquals(FOO, StringUtils.substring(SENTENCE, 0, 3)); assertEquals("o", StringUtils.substring(SENTENCE, -9, 3)); assertEquals(FOO, StringUtils.substring(SENTENCE, 0, -8)); assertEquals("o", StringUtils.substring(SENTENCE, -9, -8)); assertEquals(SENTENCE, StringUtils.substring(SENTENCE, 0, 80)); assertEquals("", StringUtils.substring(SENTENCE, 2, 2)); assertEquals("b",StringUtils.substring("abc", -2, -1)); }
@Test public void testSubstring_StringInt() { assertNull(StringUtils.substring(null, 0)); assertEquals("", StringUtils.substring("", 0)); assertEquals("", StringUtils.substring("", 2)); assertEquals("", StringUtils.substring(SENTENCE, 80)); assertEquals(BAZ, StringUtils.substring(SENTENCE, 8)); assertEquals(BAZ, StringUtils.substring(SENTENCE, -3)); assertEquals(SENTENCE, StringUtils.substring(SENTENCE, 0)); assertEquals("abc", StringUtils.substring("abc", -4)); assertEquals("abc", StringUtils.substring("abc", -3)); assertEquals("bc", StringUtils.substring("abc", -2)); assertEquals("c", StringUtils.substring("abc", -1)); assertEquals("abc", StringUtils.substring("abc", 0)); assertEquals("bc", StringUtils.substring("abc", 1)); assertEquals("c", StringUtils.substring("abc", 2)); assertEquals("", StringUtils.substring("abc", 3)); assertEquals("", StringUtils.substring("abc", 4)); }
name = StringUtils.substring( name, StringUtils.length( propertiesKeyPrefix ), StringUtils.length( name ) );
log.setError(StringUtils.substring(e.toString(), 0, 2000)); } finally { scheduleJobLogService.saveJobLog(log);
brokerResponse.getNumServersResponded(), brokerResponse.getNumServersQueried(), brokerResponse.isNumGroupsLimitReached(), brokerResponse.getExceptionsSize(), serverStats.getServerStats(), StringUtils.substring(query, 0, _queryLogLength));
@Override public StellarResult execute(String command, StellarShellExecutor executor) { StellarResult result; // expect ?functionName String functionName = StringUtils.substring(command, 1); // grab any docs for the given function Spliterator<StellarFunctionInfo> fnIterator = executor.getFunctionResolver().getFunctionInfo().spliterator(); Optional<StellarFunctionInfo> functionInfo = StreamSupport .stream(fnIterator, false) .filter(info -> StringUtils.equals(functionName, info.getName())) .findFirst(); if(functionInfo.isPresent()) { result = success(docFormat(functionInfo.get())); } else { result = error(String.format("No docs available for function '%s'", functionName)); } return result; }
private Token fail() { throw new JadeLexerException("unexpected text " + StringUtils.substring(scanner.getInput(),0,5), filename, getLineno(), templateLoader); }