List of usage examples for org.springframework.util StringUtils split
@Nullable public static String[] split(@Nullable String toSplit, @Nullable String delimiter)
From source file:org.eclipse.gemini.blueprint.extender.support.internal.ConfigUtils.java
public static boolean matchExtenderVersionRange(Bundle bundle, String header, Version versionToMatch) { Assert.notNull(bundle);/*from w w w. java 2s . c om*/ // get version range String range = bundle.getHeaders().get(header); boolean trace = log.isTraceEnabled(); // empty value = empty version = * if (!StringUtils.hasText(range)) return true; if (trace) log.trace("discovered " + header + " header w/ value=" + range); // do we have a range or not ? range = StringUtils.trimWhitespace(range); // a range means one comma int commaNr = StringUtils.countOccurrencesOf(range, COMMA); // no comma, no intervals if (commaNr == 0) { Version version = Version.parseVersion(range); return versionToMatch.equals(version); } if (commaNr == 1) { // sanity check if (!((range.startsWith(LEFT_CLOSED_INTERVAL) || range.startsWith(LEFT_OPEN_INTERVAL)) && (range.endsWith(RIGHT_CLOSED_INTERVAL) || range.endsWith(RIGHT_OPEN_INTERVAL)))) { throw new IllegalArgumentException("range [" + range + "] is invalid"); } boolean equalMin = range.startsWith(LEFT_CLOSED_INTERVAL); boolean equalMax = range.endsWith(RIGHT_CLOSED_INTERVAL); // remove interval brackets range = range.substring(1, range.length() - 1); // split the remaining string in two pieces String[] pieces = StringUtils.split(range, COMMA); if (trace) log.trace("discovered low/high versions : " + ObjectUtils.nullSafeToString(pieces)); Version minVer = Version.parseVersion(pieces[0]); Version maxVer = Version.parseVersion(pieces[1]); if (trace) log.trace("comparing version " + versionToMatch + " w/ min=" + minVer + " and max=" + maxVer); boolean result = true; int compareMin = versionToMatch.compareTo(minVer); if (equalMin) result = (result && (compareMin >= 0)); else result = (result && (compareMin > 0)); int compareMax = versionToMatch.compareTo(maxVer); if (equalMax) result = (result && (compareMax <= 0)); else result = (result && (compareMax < 0)); return result; } // more then one comma means incorrect range throw new IllegalArgumentException("range [" + range + "] is invalid"); }
From source file:org.genedb.jogra.plugins.TermRationaliser.java
public void setCvnames(String[] cvnames) { this.cvnames = cvnames; for (String c : cvnames) { String[] splitparts = StringUtils.split(c, ","); instances.put(splitparts[1], splitparts[0]); }//from ww w . jav a 2s. c om }
From source file:org.georchestra.security.HeadersManagementStrategy.java
private String sanitizeLocation(HttpServletRequest request, String location, Map<String, String> targets) { if (location.startsWith("/")) { String[] requestPath = StringUtils.split(location.substring(1), "/"); if (logger.isDebugEnabled()) { if (requestPath.length > 0) logger.debug("Sanitize location: " + requestPath[0]); }/*w ww .j a v a2 s . c om*/ if (requestPath.length > 0 && targets.containsKey(requestPath[0])) { requestPath[0] = targets.get(requestPath[0]); return StringUtils.arrayToDelimitedString(requestPath, "/"); } } return location; }
From source file:org.springframework.cloud.aws.core.env.ec2.AmazonEc2InstanceDataPropertySource.java
private static String getRootPropertyName(String propertyName) { String[] propertyTokens = StringUtils.split(propertyName, "/"); return propertyTokens != null ? propertyTokens[0] : propertyName; }
From source file:org.springframework.cloud.aws.core.env.ec2.AmazonEc2InstanceDataPropertySource.java
private Map<String, String> getUserData() { if (this.cachedUserData == null) { Map<String, String> userDataMap = new LinkedHashMap<>(); String encodedUserData = null; try {/* ww w .j av a2s. com*/ encodedUserData = EC2MetadataUtils.getUserData(); } catch (AmazonClientException e) { //Suppress exception if we are not able to contact the service, //because that is quite often the case if we run in unit tests outside the environment. LOGGER.warn("Error getting instance user-data error message is '{}'", e.getMessage()); } if (StringUtils.hasText(encodedUserData)) { byte[] bytes = Base64.decodeBase64(encodedUserData); String userData = new String(bytes, this.userDataAttributeEncoding); String[] userDataAttributes = userData.split(this.userDataAttributeSeparator); for (String userDataAttribute : userDataAttributes) { String[] userDataAttributesParts = StringUtils.split(userDataAttribute, this.userDataValueSeparator); if (userDataAttributesParts != null && userDataAttributesParts.length > 0) { String key = userDataAttributesParts[0]; String value = null; if (userDataAttributesParts.length > 1) { value = userDataAttributesParts[1]; } userDataMap.put(key, value); } } } this.cachedUserData = Collections.unmodifiableMap(userDataMap); } return this.cachedUserData; }
From source file:org.springframework.data.hadoop.boot.properties.SpringHadoopProperties.java
public void setResourceManagerAddress(String resourceManagerAddress) { String[] split = StringUtils.split(resourceManagerAddress, ":"); if (split != null && split.length == 2) { try {// ww w . j a v a 2 s .c o m resourceManagerPort = Integer.parseInt(split[1]); resourceManagerHost = split[0]; } catch (Exception e) { } } }
From source file:org.springframework.data.hadoop.boot.properties.SpringHadoopProperties.java
public void setResourceManagerSchedulerAddress(String resourceManagerSchedulerAddress) { String[] split = StringUtils.split(resourceManagerSchedulerAddress, ":"); if (split != null && split.length == 2) { try {//from w w w.ja va 2 s . c om resourceManagerSchedulerPort = Integer.parseInt(split[1]); resourceManagerSchedulerHost = split[0]; } catch (Exception e) { } } }
From source file:org.springframework.osgi.extender.support.internal.ConfigUtils.java
public static boolean matchExtenderVersionRange(Bundle bundle, String header, Version versionToMatch) { Assert.notNull(bundle);/*from ww w. jav a 2s . c om*/ // get version range String range = (String) bundle.getHeaders().get(header); boolean trace = log.isTraceEnabled(); // empty value = empty version = * if (!StringUtils.hasText(range)) return true; if (trace) log.trace("discovered " + header + " header w/ value=" + range); // do we have a range or not ? range = StringUtils.trimWhitespace(range); // a range means one comma int commaNr = StringUtils.countOccurrencesOf(range, COMMA); // no comma, no intervals if (commaNr == 0) { Version version = Version.parseVersion(range); return versionToMatch.equals(version); } if (commaNr == 1) { // sanity check if (!((range.startsWith(LEFT_CLOSED_INTERVAL) || range.startsWith(LEFT_OPEN_INTERVAL)) && (range.endsWith(RIGHT_CLOSED_INTERVAL) || range.endsWith(RIGHT_OPEN_INTERVAL)))) { throw new IllegalArgumentException("range [" + range + "] is invalid"); } boolean equalMin = range.startsWith(LEFT_CLOSED_INTERVAL); boolean equalMax = range.endsWith(RIGHT_CLOSED_INTERVAL); // remove interval brackets range = range.substring(1, range.length() - 1); // split the remaining string in two pieces String[] pieces = StringUtils.split(range, COMMA); if (trace) log.trace("discovered low/high versions : " + ObjectUtils.nullSafeToString(pieces)); Version minVer = Version.parseVersion(pieces[0]); Version maxVer = Version.parseVersion(pieces[1]); if (trace) log.trace("comparing version " + versionToMatch + " w/ min=" + minVer + " and max=" + maxVer); boolean result = true; int compareMin = versionToMatch.compareTo(minVer); if (equalMin) result = (result && (compareMin >= 0)); else result = (result && (compareMin > 0)); int compareMax = versionToMatch.compareTo(maxVer); if (equalMax) result = (result && (compareMax <= 0)); else result = (result && (compareMax < 0)); return result; } // more then one comma means incorrect range throw new IllegalArgumentException("range [" + range + "] is invalid"); }
From source file:org.springframework.xd.dirt.plugins.job.ModuleJobLauncher.java
public void executeBatchJob() { Collection<String> names = registry.getJobNames(); for (String curName : names) { String[] jobNames = StringUtils.split(curName, JOB_NAME_DELIMITER); if (jobNames[NAME_INDEX].equals(groupName)) { try { launcher.run(registry.getJob(curName), jobParameters); } catch (Exception e) { logger.error("An error occured while starting job " + curName, e); }// w w w . j a va2 s. co m } } }
From source file:org.springframework.yarn.examples.ActivatorTests.java
@Test public void testAppInstallSubmit() throws Exception { String ID = "foo-1"; String BASE = "/apps/"; setYarnClient(buildYarnClient());//from ww w. j a va 2s. c om String[] installAppArgs = new String[] { "--spring.hadoop.fsUri=" + getConfiguration().get("fs.defaultFS"), "--spring.hadoop.resourceManagerAddress=" + getConfiguration().get("yarn.resourcemanager.address"), "--spring.yarn.client.files[0]=file:build/libs/test-install-submit-appmaster-2.0.0.BUILD-SNAPSHOT.jar", "--spring.yarn.client.files[1]=file:build/libs/test-install-submit-container-2.0.0.BUILD-SNAPSHOT.jar" }; Properties appProperties = new Properties(); appProperties.setProperty("spring.yarn.applicationDir", BASE + ID + "/"); YarnPushApplication installApp = new YarnPushApplication(); installApp.applicationVersion(ID); installApp.applicationBaseDir(BASE); installApp.configFile("application.properties", appProperties); installApp.run(installAppArgs); listFiles(); catFile(BASE + ID + "/application.properties"); String rm = getConfiguration().get("yarn.resourcemanager.address"); String[] split = StringUtils.split(rm, ":"); String[] submitAppArgs = new String[] { "--spring.yarn.applicationDir=" + BASE + ID + "/", "--spring.hadoop.fsUri=" + getConfiguration().get("fs.defaultFS"), "--spring.hadoop.resourceManagerHost=" + split[0], "--spring.hadoop.resourceManagerAddress=" + getConfiguration().get("yarn.resourcemanager.address"), "--spring.hadoop.resourceManagerSchedulerAddress=" + getConfiguration().get("yarn.resourcemanager.scheduler.address") }; YarnSubmitApplication submitApp = new YarnSubmitApplication(); submitApp.applicationVersion(ID); submitApp.applicationBaseDir(BASE); ApplicationId applicationId = submitApp.run(submitAppArgs); YarnApplicationState state = waitState(applicationId, 2, TimeUnit.MINUTES, YarnApplicationState.FINISHED); assertThat(state, is(YarnApplicationState.FINISHED)); List<Resource> resources = ContainerLogUtils.queryContainerLogs(getYarnCluster(), applicationId); assertThat(resources, notNullValue()); assertThat(resources.size(), is(6)); for (Resource res : resources) { File file = res.getFile(); String content = ContainerLogUtils.getFileContent(file); if (file.getName().endsWith("stdout")) { assertThat(file.length(), greaterThan(0l)); if (file.getName().equals("Container.stdout")) { assertThat(content, containsString("Hello from ActivatorPojo")); } } else if (file.getName().endsWith("stderr")) { assertThat("stderr file is not empty: " + content, file.length(), is(0l)); } } }