List of usage examples for org.apache.commons.lang3 StringUtils lastIndexOf
public static int lastIndexOf(final CharSequence seq, final CharSequence searchSeq)
Finds the last index within a CharSequence, handling null .
From source file:com.nike.cerberus.service.SafeDepositBoxService.java
/** * Deletes all of the secrets from Vault stored at the safe deposit box's path. * * @param path path to start deleting at. *///from w w w . ja v a2s. c o m private void deleteAllSecrets(final String path) { try { String fixedPath = path; if (StringUtils.endsWith(path, "/")) { fixedPath = StringUtils.substring(path, 0, StringUtils.lastIndexOf(path, "/")); } final VaultListResponse listResponse = vaultAdminClient.list(fixedPath); final List<String> keys = listResponse.getKeys(); if (keys == null || keys.isEmpty()) { return; } for (final String key : keys) { if (StringUtils.endsWith(key, "/")) { final String fixedKey = StringUtils.substring(key, 0, key.lastIndexOf("/")); deleteAllSecrets(fixedPath + "/" + fixedKey); } else { vaultAdminClient.delete(fixedPath + "/" + key); } } } catch (VaultClientException vce) { throw ApiException.newBuilder().withApiErrors(DefaultApiError.SERVICE_UNAVAILABLE) .withExceptionCause(vce).withExceptionMessage("Failed to delete secrets from Vault.").build(); } }
From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineFactory.java
/** * Instantiates, initializes and returns the {@link DelayedResponseOperatorWaitStrategy} configured for the {@link DelayedResponseOperator} * whose {@link MicroPipelineComponentConfiguration configuration} is provided when calling this method. * @param delayedResponseOperatorCfg/*from www . j av a 2s . c o m*/ * @return */ protected DelayedResponseOperatorWaitStrategy getResponseWaitStrategy( final MicroPipelineComponentConfiguration delayedResponseOperatorCfg) throws RequiredInputMissingException, UnknownWaitStrategyException { ///////////////////////////////////////////////////////////////////////////////////// // validate input if (delayedResponseOperatorCfg == null) throw new RequiredInputMissingException("Missing required delayed response operator configuration"); if (delayedResponseOperatorCfg.getSettings() == null) throw new RequiredInputMissingException("Missing required delayed response operator settings"); String strategyName = StringUtils.lowerCase(StringUtils.trim(delayedResponseOperatorCfg.getSettings() .getProperty(DelayedResponseOperator.CFG_WAIT_STRATEGY_NAME))); if (StringUtils.isBlank(strategyName)) throw new RequiredInputMissingException( "Missing required strategy name expected as part of operator settings ('" + DelayedResponseOperator.CFG_WAIT_STRATEGY_NAME + "')"); // ///////////////////////////////////////////////////////////////////////////////////// if (logger.isDebugEnabled()) logger.debug("Settings provided for strategy '" + strategyName + "'"); Properties strategyProperties = new Properties(); for (Enumeration<Object> keyEnumerator = delayedResponseOperatorCfg.getSettings().keys(); keyEnumerator .hasMoreElements();) { String key = (String) keyEnumerator.nextElement(); if (StringUtils.startsWith(key, DelayedResponseOperator.CFG_WAIT_STRATEGY_SETTINGS_PREFIX)) { String waitStrategyCfgKey = StringUtils.substring(key, StringUtils.lastIndexOf(key, ".") + 1); if (StringUtils.isNoneBlank(waitStrategyCfgKey)) { String waitStrategyCfgValue = delayedResponseOperatorCfg.getSettings().getProperty(key); strategyProperties.put(waitStrategyCfgKey, waitStrategyCfgValue); if (logger.isDebugEnabled()) logger.debug("\t" + waitStrategyCfgKey + ": " + waitStrategyCfgValue); } } } if (StringUtils.equalsIgnoreCase(strategyName, MessageCountResponseWaitStrategy.WAIT_STRATEGY_NAME)) { MessageCountResponseWaitStrategy strategy = new MessageCountResponseWaitStrategy(); strategy.initialize(strategyProperties); return strategy; } else if (StringUtils.equalsIgnoreCase(strategyName, TimerBasedResponseWaitStrategy.WAIT_STRATEGY_NAME)) { TimerBasedResponseWaitStrategy strategy = new TimerBasedResponseWaitStrategy(); strategy.initialize(strategyProperties); return strategy; } else if (StringUtils.equalsIgnoreCase(strategyName, OperatorTriggeredWaitStrategy.WAIT_STRATEGY_NAME)) { OperatorTriggeredWaitStrategy strategy = new OperatorTriggeredWaitStrategy(); strategy.initialize(strategyProperties); return strategy; } throw new UnknownWaitStrategyException("Unknown wait strategy '" + strategyName + "'"); }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TestMultithreadedTableProvider.java
private static Map<String, String> buildOffsetMap(Map<TableRuntimeContext, Map<String, String>> partitions, final boolean preNonIncremental) { final Map<String, String> offsets = new HashMap<>(); partitions.forEach((part, off) -> { String offsetKey = part.getOffsetKey(); if (preNonIncremental) { // before non-incremental mode, offset keys didn't have the final portion (usingNonIncrementalLoad) // so remove the final term final int index = StringUtils.lastIndexOf(offsetKey, TableRuntimeContext.OFFSET_TERM_SEPARATOR); offsetKey = offsetKey.substring(0, index); }/*from w w w . java 2s. co m*/ offsets.put(offsetKey, off == null ? null : OffsetQueryUtil.getOffsetFormat(off)); }); return offsets; }
From source file:nl.kpmg.lcm.server.backend.AbstractBackend.java
private void processDataItemList(String uri, List<String> dataItemList) { URI parsedUri = parseUri(uri); String path = processPath(parsedUri); int index = StringUtils.lastIndexOf(path, "/"); String item = path.substring(index + 1, path.length()); Pattern namePattern = Pattern.compile(item.replace("*", ".*")); for (String dataItemName : dataItemList) { if (namePattern.matcher(dataItemName).matches()) { String uriItem = uri.replace(item, dataItemName); processDataItemURI(uriItem); }/*from w ww . j a v a2s . c o m*/ } }
From source file:nl.kpmg.lcm.server.backend.AbstractBackend.java
private List getDataItems(String uri) { URI parsedUri = parseUri(uri); if (parsedUri == null) { return null; }// w ww .j a v a 2 s . c om String path = processPath(parsedUri); String subPath = ""; int index = StringUtils.lastIndexOf(path, "/"); if (index != -1) { subPath = path.substring(0, index); } if (subPath.contains("*")) { LOGGER.error( "Error! URI has invalid syntax. Wildcard symbol is used in the path:" + parsedUri.toString()); return null; } String storageName = parsedUri.getHost() != null ? parsedUri.getHost() : parsedUri.getAuthority(); try { return loadDataItems(storageName, subPath); } catch (Exception ex) { LOGGER.warn("Unable to load data items for storage: " + storageName + " and subPath: " + subPath + ". Error message: " + ex.getMessage()); return null; } }
From source file:nl.kpmg.lcm.server.data.s3.S3FileSystemAdapter.java
@Override public List listFileNames(String subPath) throws IOException { if (subPath.length() > 0 && subPath.charAt(subPath.length() - 1) != '/') { subPath = subPath + '/'; }/* w w w .j a va 2 s .c om*/ LinkedList<String> fileNameList = new LinkedList(); ObjectListing listing; do { listing = s3Client.listObjects(bucketName, subPath); List<S3ObjectSummary> objectSummaryList = listing.getObjectSummaries(); for (S3ObjectSummary objectSummary : objectSummaryList) { String key = objectSummary.getKey(); int index = StringUtils.lastIndexOf(key, "/"); // Some of the keys contain '/'. For example "test/test1.csv". Some others don`t. For // example "example1.txt". If a key doesn`t contain '/' the value of index would be -1. That // is why we need the following check. if (index == -1) { index = 0; } String itemName = key.substring(index); fileNameList.add(itemName); } } while (listing.isTruncated()); return fileNameList; }
From source file:org.asqatasun.ruleimplementation.link.AbstractDownloadableLinkRuleImplementation.java
/** * //from w w w .j a va2 s . c o m * @param uri * @return whether the current link has a proper extension (link.html) */ private boolean isLinkWithProperExtension(URI uri) { if (StringUtils.isNotBlank(uri.getQuery())) { return false; } String path = uri.getPath(); if (StringUtils.isBlank(path) || StringUtils.equals(path, SLASH_CHAR)) { return false; } int lastSlash = StringUtils.lastIndexOf(path, SLASH_CHAR); return StringUtils.substring(path, lastSlash).contains(POINT_CHAR); }
From source file:org.asqatasun.rules.test.AbstractRuleImplementationTestCase.java
@Override public String getName() { int lastPointIndex = StringUtils.lastIndexOf(ruleImplementationClassName, ".") + 1; String className = StringUtils.substring(ruleImplementationClassName, lastPointIndex); return StringUtils.replace(className, "Rule", "-"); }
From source file:org.eclipse.ebr.maven.EclipseIpLogUtil.java
private String getProjectLocation(final Model recipePom, final Xpp3Dom existingIpLog) { final String existingValue = getProjectInfo(existingIpLog, "location"); if (existingValue != null) return existingValue; final Scm scm = recipePom.getScm(); if (scm != null) { final String url = getScmUrl(scm); // by definition, we return everything after to the last ".git" if (url != null) { final int lastIndexOf = StringUtils.lastIndexOf(url, ".git"); if (lastIndexOf >= 0) return StringUtils.removeStart(url.substring(lastIndexOf + 4), "/"); return url; }/* w w w .jav a 2 s .c o m*/ } return null; }
From source file:org.eclipse.ebr.maven.EclipseIpLogUtil.java
private String getProjectRepository(final Model recipePom, final Xpp3Dom existingIpLog) { final String existingValue = getProjectInfo(existingIpLog, "repository"); if (existingValue != null) return existingValue; final Scm scm = recipePom.getScm(); if (scm != null) { final String url = getScmUrl(scm); // by definition, we return everything up to the last ".git" if (url != null) { final int lastIndexOf = StringUtils.lastIndexOf(url, ".git"); if (lastIndexOf >= 0) return url.substring(0, lastIndexOf + 4); return url; }//from w ww . ja v a 2 s .c om } return null; }