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:com.omnigon.aem.handlebars.helpers.UniqueIdHelper.java
private String formatUniqueId(String uniqueId) { String formattedUniqueId = StringUtils.substring(UNIQUE_ID_PREFIX + uniqueId, 0, UNIQUE_ID_LENGTH); return formattedUniqueId; }
From source file:io.github.lxgaming.teleportbow.commands.AbstractCommand.java
@Override public final Optional<Text> getShortDescription(CommandSource commandSource) { if (StringUtils.length(getDescription()) > 53) { return Optional.of(Text.of(StringUtils.substring(getDescription(), 0, 50), "...")); }//from w ww . j av a 2 s.c o m return Optional.of(Text.of(StringUtils.defaultIfBlank(getDescription(), "No description provided"))); }
From source file:de.micromata.genome.util.types.Converter.java
/** * Kuerzt den Text auf angegebene UTF8 byte Laenge. Hierbei wird nicht genau gekuerzt, sondern die resultierenden * Bytes koennen noch kuerzer angegebene Laenge sein. * * @param text the text//from www. j av a 2s .c om * @param length the length * @return the string */ public static String trimUtf8(String text, int length) { if (text == null) { return ""; } text = StringUtils.substring(text, 0, length); byte[] bytes = bytesFromString(text); if (bytes.length <= length) { return text; } int diff = bytes.length - length; int newl = text.length() - diff; if (newl <= 0) { return trimUtf8Exact(text, length); } return StringUtils.substring(text, 0, newl); }
From source file:com.handpay.ibenefit.framework.util.PropertyFilter.java
/** * //from ww w . j av a2 s . c o m * @param defalutObjectName default object name * @param filterName property name * @param value the value of the property */ public PropertyFilter(final String defalutObjectName, final String filterName, final String value) { String matchTypeStr = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(matchTypeStr, 0, matchTypeStr.length() - 1); String propertyTypeCode = StringUtils.substring(matchTypeStr, matchTypeStr.length() - 1, matchTypeStr.length()); this.filterName = filterName; matchType = Enum.valueOf(MatchType.class, matchTypeCode); propertyType = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); propertyName = StringUtils.substringAfter(filterName, "_"); if (propertyName.indexOf(".") != -1) { String[] array = propertyName.split("\\."); objectName = array[0]; propertyName = array[1]; } else { objectName = defalutObjectName; } propertyValueString = value; try { this.propertyValue = ReflectUtils.convertStringToObject(value, propertyType); //Handle Date type if (propertyTypeCode.equals("D")) { //Set to the begin of the date or end of the date if (matchType == MatchType.GE || matchType == MatchType.GT) { this.propertyValue = DateUtils.getBeginOfTheDate((Date) this.propertyValue); } else if (matchType == MatchType.LE || matchType == MatchType.LT) { this.propertyValue = DateUtils.getEndOfTheDate((Date) this.propertyValue); } } if (matchType == PropertyFilter.MatchType.IC || matchType == PropertyFilter.MatchType.NC) { String[] values = value.split(","); propertyValues = new ArrayList(values.length); for (String v : values) { propertyValues.add(ReflectUtils.convertStringToObject(v, propertyType)); } } } catch (Exception e) { } }
From source file:fi.helsinki.moodi.service.importing.MoodleCourseBuilder.java
private String getShortName(String realisationName, int realisationId) { return StringUtils.substring(realisationName, 0, 8) + " " + realisationId; }
From source file:com.norconex.commons.lang.file.FileUtil.java
/** * Converts a "safe" file name originally created with * {@link #toSafeFileName(String)} into its original string. * @param safeFileName the file name to convert to its origianl form * @return original string//ww w . ja v a 2 s . c o m */ public static String fromSafeFileName(String safeFileName) { if (safeFileName == null) { return null; } StringBuilder b = new StringBuilder(); for (int i = 0; i < safeFileName.length(); i++) { char ch = safeFileName.charAt(i); if (ch == '_') { String intVal = StringUtils.substring(safeFileName, i + 1, StringUtils.indexOf(safeFileName, '_', i + 1)); b.append((char) NumberUtils.toInt(intVal)); i += intVal.length() + 1; } else { b.append(ch); } } return b.toString(); }
From source file:com.github.dactiv.fear.commons.AuthCoder.java
/** * /*from w w w . j a v a 2 s. c o m*/ * * @param value ? * @param key * @param randomKeyLength ? ? 0-32???? * ???iv?? * ? = 16 randomKeyLength 0 ?? * @param encoding ? * @return ? */ public static String decode(String value, String key, int randomKeyLength, String encoding) throws UnsupportedEncodingException { key = DigestUtils.md5Hex(key.getBytes()); String keya = DigestUtils.md5Hex(StringUtils.substring(key, 0, 16).getBytes()); String keyb = DigestUtils.md5Hex(StringUtils.substring(key, 16, 16 + 16).getBytes()); String keyc = randomKeyLength > 0 ? StringUtils.substring(value, 0, randomKeyLength) : ""; String cryptKey = keya + DigestUtils.md5Hex((keya + keyc).getBytes()); int cryptKeyLen = cryptKey.length(); value = new String(Base64.decodeBase64((StringUtils.substring(value, randomKeyLength))), encoding); int stringLen = value.length(); List<Integer> rndKey = new ArrayList<>(); StringBuilder result = new StringBuilder(); Integer[] box = new Integer[256]; for (int i = 0; i < box.length; i++) { box[i] = i; } for (int i = 0; i <= 255; i++) { rndKey.add((int) cryptKey.charAt(i % cryptKeyLen)); } for (int j = 0, i = 0; i < 256; i++) { j = (j + box[i] + rndKey.get(i)) % 256; int tmp = box[i]; box[i] = box[j]; box[j] = tmp; } for (int k = 0, j = 0, i = 0; i < stringLen; i++) { k = (k + 1) % 256; j = (j + box[k]) % 256; int tmp = box[k]; box[k] = box[j]; box[j] = tmp; int a = (int) value.charAt(i); int b = box[(box[k] + box[j]) % 256]; char r = (char) (a ^ b); result.append(r); } if ((NumberUtils.toInt(StringUtils.substring(result.toString(), 0, 10), -1) == 0 || NumberUtils.toInt(StringUtils.substring(result.toString(), 0, 10), 0) - System.currentTimeMillis() / 1000 > 0) && StringUtils.substring(result.toString(), 10, 10 + 16) .equals(StringUtils.substring( DigestUtils .md5Hex((StringUtils.substring(result.toString(), 26) + keyb).getBytes()), 0, 16))) { return StringUtils.substring(result.toString(), 26); } else { return ""; } }
From source file:com.streamsets.pipeline.lib.salesforce.BulkRecordCreator.java
public String createRecord(Object source, BatchMaker batchMaker, int recordIndex) throws StageException { XMLEventReader reader = (XMLEventReader) source; String nextSourceOffset;/*from w w w. j a v a2s . co m*/ try { // Pull the root map from the reader Field field = pullMap(reader); // Get the offset from the record Object newRawOffset = getIgnoreCase(field.getValueAsMap(), conf.offsetColumn); if (newRawOffset == null) { throw new StageException(Errors.FORCE_22, conf.offsetColumn); } String newOffset; if (newRawOffset instanceof Date) { newOffset = dateFormat.format((Date) newRawOffset); } else { newOffset = newRawOffset.toString(); } nextSourceOffset = fixOffset(conf.offsetColumn, newOffset); final String sourceId = StringUtils.substring(conf.soqlQuery.replaceAll("[\n\r]", " "), 0, 100) + "::rowCount:" + recordIndex + (StringUtils.isEmpty(conf.offsetColumn) ? "" : ":" + nextSourceOffset); Record record = context.createRecord(sourceId); record.set(field); record.getHeader().setAttribute(SOBJECT_TYPE_ATTRIBUTE, sobjectType); batchMaker.addRecord(record); return nextSourceOffset; } catch (XMLStreamException e) { throw new StageException(Errors.FORCE_37, e); } }
From source file:de.micromata.genome.chronos.spi.jdbc.JobResultDO.java
public String getResultStringForDB() { return StringUtils.substring(getResultString(), 0, 1290); }
From source file:de.micromata.genome.logging.spi.ifiles.IndexDirectory.java
private static String fileToStoredName(File logFile) { String name = getDirectoryNameFromFile(logFile); String lwwrite = StringUtils.substring(name, 0, LOG_FILE_NAME_SIZE); lwwrite = StringUtils.rightPad(lwwrite, LOG_FILE_NAME_SIZE); return lwwrite; }