List of usage examples for org.apache.commons.lang3 StringUtils substring
public static String substring(final String str, int start, int end)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start/end n characters from the end of the String.
The returned substring starts with the character in the start position and ends before the end position.
From source file:am.ik.categolj2.core.web.UserAgents.java
public static String getUserAgent(HttpServletRequest request) { String userAgent = StringUtils.substring(request.getHeader(HttpHeaders.USER_AGENT), 0, 256); return userAgent; }
From source file:am.ik.categolj2.core.web.RemoteAddresses.java
public static String getRemoteAddress(HttpServletRequest request) { String forwardedFor = request.getHeader(HttpHeaders.X_FORWARDED_FOR); String result;/*from www . j a va2s . c o m*/ if (forwardedFor != null) { result = forwardedFor; } else { result = request.getRemoteAddr(); } return StringUtils.substring(result, 0, 128); }
From source file:de.jcup.egradle.core.util.StringUtilsAccess.java
public static String substring(String str, int start, int end) { return StringUtils.substring(str, start, end); }
From source file:de.micromata.genome.util.strings.MiscStringUtils.java
/** * Shorten a String from the right side/*from w ww. j a v a2 s . co m*/ * * @param s the string * @param maxLength the max length of the string * @return the cutted string */ public static String cutRight(String s, int maxLength) { return StringUtils.substring(s, 0, maxLength); }
From source file:com.mirth.connect.server.util.Pre22PasswordChecker.java
/** * The pre-2.2 password has been migrated to the following * format:// w w w . jav a 2s .c om * * SALT_ + 8-bit salt + base64(sha(salt + password)) * * To compare: * * 1. Strip the known pre-2.2 prefix * 2. Get the first 8-bits and Base64 decode it, this the salt * 3. Get the remaining bits and Base64 decode it, this is the hash * 4. Pass it into the pre-2.2 password checker algorithm * * @param plainPassword The plain text password to check against the hash * @param encodedPassword The hashed password * @return true if the password matches the hash using the pre-2.2 algorithm, false otherwise */ public static boolean checkPassword(String plainPassword, String encodedPassword) throws Exception { String saltHash = StringUtils.substringAfter(encodedPassword, SALT_PREFIX); String encodedSalt = StringUtils.substring(saltHash, 0, SALT_LENGTH); byte[] decodedSalt = Base64.decodeBase64(encodedSalt); byte[] decodedHash = Base64.decodeBase64(StringUtils.substring(saltHash, encodedSalt.length())); if (Arrays.equals(decodedHash, DigestUtils.sha(ArrayUtils.addAll(decodedSalt, plainPassword.getBytes())))) { return true; } return false; }
From source file:bear.vcs.CommandLineResult.java
private static String cut(String script) { if (script == null) return null; try {// w ww . j av a2 s. c om String next = Variables.LINE_SPLITTER.split(script).iterator().next(); return StringUtils.substring(next, 0, 80); } catch (Exception e) { return script.trim(); } }
From source file:com.eryansky.common.orm.core.PropertyFilters.java
/** * ?// w ww. j ava 2 s .com * <p> * * </p> * <code> * PropertyFilters.get("EQS_propertyName","maurice") * </code> * * @param expression ? * @param matchValue * * @return {@link PropertyFilter} */ @SuppressWarnings("static-access") public static PropertyFilter get(String expression, String matchValue) { Assert.hasText(expression, "??"); String restrictionsNameAndClassType = StringUtils.substringBefore(expression, "_"); String restrictionsName = StringUtils.substring(restrictionsNameAndClassType, 0, restrictionsNameAndClassType.length() - 1); String classType = StringUtils.substring(restrictionsNameAndClassType, restrictionsNameAndClassType.length() - 1, restrictionsNameAndClassType.length()); FieldType FieldType = null; try { FieldType = FieldType.valueOf(classType); } catch (Exception e) { throw new IllegalAccessError( "[" + expression + "]??,?:" + classType); } String[] propertyNames = null; if (StringUtils.contains(expression, "_OR_")) { String temp = StringUtils.substringAfter(expression, restrictionsNameAndClassType + "_"); propertyNames = StringUtils.splitByWholeSeparator(temp, "_OR_"); } else { propertyNames = new String[1]; propertyNames[0] = StringUtils.substringAfterLast(expression, "_"); } return new PropertyFilter(restrictionsName, FieldType, propertyNames, matchValue); }
From source file:com.github.dactiv.orm.core.PropertyFilters.java
/** * ?//from w w w.j a v a2 s . c o m * <p> * * </p> * <code> * PropertyFilters.build("EQS_propertyName","maurice") * </code> * * @param expression ? * @param matchValue * * @return {@link PropertyFilter} */ @SuppressWarnings("static-access") public static PropertyFilter build(String expression, String matchValue) { Assert.hasText(expression, "??"); String restrictionsNameAndClassType = StringUtils.substringBefore(expression, "_"); String restrictionsName = StringUtils.substring(restrictionsNameAndClassType, 0, restrictionsNameAndClassType.length() - 1); String classType = StringUtils.substring(restrictionsNameAndClassType, restrictionsNameAndClassType.length() - 1, restrictionsNameAndClassType.length()); FieldType FieldType = null; try { FieldType = FieldType.valueOf(classType); } catch (Exception e) { throw new IllegalAccessError( "[" + expression + "]??,?:" + classType); } String[] propertyNames = null; if (StringUtils.contains(expression, "_OR_")) { String temp = StringUtils.substringAfter(expression, restrictionsNameAndClassType + "_"); propertyNames = StringUtils.splitByWholeSeparator(temp, "_OR_"); } else { propertyNames = new String[1]; propertyNames[0] = StringUtils.substringAfterLast(expression, "_"); } return new PropertyFilter(restrictionsName, FieldType, propertyNames, matchValue); }
From source file:com.ctrip.infosec.rule.rabbitmq.CallbackMessageSender.java
public void sendToPD(RiskResult result) { String routingKey = StringUtils.substring(result.getEventPoint(), 2, 5); String message = JSON.toJSONString(result); logger.info(Contexts.getLogPrefix() + "send callback message, routingKey=" + routingKey + ", message=" + message);/*from www.j a v a 2s . co m*/ template.convertAndSend(routingKey, message); logger.info(Contexts.getLogPrefix() + "send callback message, OK."); }
From source file:com.omnigon.aem.handlebars.helpers.UniqueId.java
public static String generateUniqueId(String directoryPath) { byte[] bytesDirectoryPath = null; MessageDigest md = null;//from w w w . j av a2 s .com try { bytesDirectoryPath = directoryPath.getBytes(CharEncoding.UTF_8); md = MessageDigest.getInstance(MESSAGE_DIGEST_TYPE); } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { logger.error(e.getMessage(), e); return StringUtils.EMPTY; } md.reset(); md.update(bytesDirectoryPath); String uniqueId = DatatypeConverter.printHexBinary(md.digest()); return StringUtils.substring(uniqueId, 0, UNIQUE_ID_LENGTH); }