List of usage examples for org.apache.commons.lang StringUtils split
public static String[] split(String str, String separatorChars)
Splits the provided text into an array, separators specified.
From source file:com.hangum.tadpole.application.start.update.checker.NewVersionChecker.java
/** * get version info data//from www . j a v a 2s. co m * * @return */ public boolean getVersionInfoData() { InputStream is = null; try { is = new URL(CHECK_URI).openConnection().getInputStream(); String strJson = IOUtils.toString(is); if (logger.isDebugEnabled()) { logger.debug("==[start]==================================="); logger.debug(strJson); logger.debug("==[end]==================================="); } Gson gson = new Gson(); newVersionObj = gson.fromJson(strJson, NewVersionObject.class); if (newVersionObj == null) return false; String[] arryCurVer = StringUtils.split(SystemDefine.MAJOR_VERSION, "."); String[] arryNewVer = StringUtils.split(newVersionObj.getMajorVer(), "."); for (int i = 0; i < arryCurVer.length; i++) { if (Integer.parseInt(arryNewVer[i]) > Integer.parseInt(arryCurVer[i])) { return true; } } } catch (Exception e) { logger.error(String.format("New version checkerer %s.", e.getMessage())); } finally { if (is != null) { try { // IOUtils.toString(is); IOUtils.closeQuietly(is); } catch (Exception e) { //igoner excetpion } } } return false; }
From source file:edu.ku.brc.ui.ColorWrapper.java
/** * Parses a comma separated String and creates a color and sets it internally * @param rgbStr the string to be parsed ("100, 128, 45") *//* ww w. j a v a 2 s. c o m*/ public Color setRGB(final String rgbStr) { if (rgbStr == null) { throw new IllegalArgumentException("ColorWrapper - The Color string is null!"); } String[] rgbVals = StringUtils.split(rgbStr, " ,"); if (rgbVals.length == 3) { // We could check for numeric here if (StringUtils.isNumeric(rgbVals[0]) && StringUtils.isNumeric(rgbVals[1]) && StringUtils.isNumeric(rgbVals[2])) { int r = Integer.parseInt(rgbVals[0]); int g = Integer.parseInt(rgbVals[1]); int b = Integer.parseInt(rgbVals[2]); setRGB(r, g, b); } else { setRGB(255, 255, 255); //throw new IllegalArgumentException("ColorWrapper - one of the values is not numeric r["+rgbVals[0]+"] g["+rgbVals[1]+"] b["+rgbVals[2]+"]"); log.error("ColorWrapper - one of the values is not numeric [" + rgbStr + "] r[" + rgbVals[0] + "] g[" + rgbVals[1] + "] b[" + rgbVals[2] + "]"); } } else if (StringUtils.isNotEmpty(rgbStr)) { throw new IllegalArgumentException("ColorWrapper - The Color string doesn't parse [" + rgbStr + "]"); } return color; }
From source file:gov.nih.nci.cacis.ip.mirthconnect.ftp.FTPMapping.java
private void addFTPSiteToMap(String ftpInfoStr) { final String[] ftpParams = StringUtils.split(ftpInfoStr, ','); if (ftpParams.length != 6) { throw new ApplicationRuntimeException( "FTP site properties must be in the form of '<site>,<port>,<user>,<password>,<directory>'"); }/*from w ww. ja v a 2 s . c o m*/ final FTPInfo ftpInfo = new FTPInfo(); ftpInfo.setProtocol(ftpParams[0]); ftpInfo.setSite(ftpParams[1]); ftpInfo.setPort(Integer.valueOf(ftpParams[2])); ftpInfo.setUserName(ftpParams[3]); ftpInfo.setPassword(ftpParams[4]); ftpInfo.setRootDirectory(ftpParams[5]); ftpInfoMap.put(ftpInfo.getSite(), ftpInfo); }
From source file:com.alibaba.otter.manager.web.home.module.action.AutoKeeperClusterAction.java
public void doEdit(@FormGroup("autokeeperClusterInfo") Group autokeeperClusterInfo, @FormField(name = "formAutokeeperClusterError", group = "autokeeperClusterInfo") CustomErrors err, Navigator nav) throws Exception { AutoKeeperCluster autoKeeperCluster = new AutoKeeperCluster(); autokeeperClusterInfo.setProperties(autoKeeperCluster); String zkClustersString = autokeeperClusterInfo.getField("zookeeperClusters").getStringValue(); String[] zkClusters = StringUtils.split(zkClustersString, ";"); autoKeeperCluster.setServerList(Arrays.asList(zkClusters)); try {/*from www .j av a2 s . c o m*/ autoKeeperClusterService.modifyAutoKeeperCluster(autoKeeperCluster); } catch (RepeatConfigureException rce) { err.setMessage("invalidChannelName"); return; } nav.redirectTo(WebConstant.AUTO_KEEPER_CLUSTERS_LINK); }
From source file:hudson.plugins.copyartifact.CopyArtifactPermissionProperty.java
/** * Constructor/* ww w . ja va 2 s.c om*/ * * @param projectNames comma-separated project names that can copy artifacts of this project. */ @DataBoundConstructor public CopyArtifactPermissionProperty(String projectNames) { List<String> rawProjectNameList = Arrays .asList((projectNames != null) ? StringUtils.split(projectNames, ',') : new String[0]); projectNameList = new ArrayList<String>(rawProjectNameList.size()); for (String rawProjectName : rawProjectNameList) { if (StringUtils.isBlank(rawProjectName)) { continue; } projectNameList.add(StringUtils.trim(rawProjectName)); } }
From source file:net.kamhon.ieagle.function.config.BasicAppConfig.java
public List<String> exceptionNotToLog() { List<String> exceptions = new ArrayList<String>(); String property = env.getProperty("exceptionNotToLog"); if (StringUtils.isNotBlank(property)) { String[] ss = StringUtils.split(property, ','); for (String s : ss) { exceptions.add(s);/*from w w w . j a v a 2 s . c om*/ } } else { exceptions.add("net.kamhon.ieagle.exception.ValidatorException"); exceptions.add("net.kamhon.ieagle.exception.InvalidCredentialsException"); } return exceptions; }
From source file:edu.ku.brc.specify.toycode.ResFileCompare.java
@SuppressWarnings("unchecked") public void fixPropertiesFiles(final String baseFileName, final String lang, final boolean doBranch) { System.out.println("-------------------- " + baseFileName + " --------------------"); File engFile;//from ww w.ja va2 s . c o m File lngFile; String engName = String.format("src/%s_en.properties", baseFileName); String langName = String.format("src/%s_%s.properties", baseFileName, lang); if (doBranch) { engFile = new File( String.format("/home/rods/workspace/Specify_6202SF/src/%s_en.properties", baseFileName)); lngFile = new File( String.format("/home/rods/workspace/Specify_6202SF/src/%s_%s.properties", baseFileName, lang)); } else { engFile = new File(engName); lngFile = new File(langName); } try { List<String> engList = (List<String>) FileUtils.readLines(engFile, "UTF8"); List<String> lngListTmp = (List<String>) FileUtils.readLines(lngFile, "UTF8"); int lineCnt = -1; HashMap<String, String> transHash = new HashMap<String, String>(); for (String line : lngListTmp) { lineCnt++; if (line.startsWith("#") || StringUtils.deleteWhitespace(line).length() < 3 || line.indexOf('=') == -1) { continue; } String[] toks = StringUtils.split(line, '='); if (toks.length > 1) { if (toks.length == 2) { transHash.put(toks[0], toks[1]); } else { StringBuilder sb = new StringBuilder(); for (int i = 1; i < toks.length; i++) { sb.append(String.format("%s=", toks[i])); } sb.setLength(sb.length() - 1); // chomp extra '=' transHash.put(toks[0], sb.toString()); } } else { log.error("Skipping:[" + line + "] Line:" + lineCnt); } } log.info(String.format("Lines Eng: %d; Terms Hash size: %s: %d", engList.size(), lang, transHash.size())); File dir = new File("translations"); if (!dir.exists()) { if (!dir.mkdir()) { log.error("Unable to create directory[" + dir.getAbsolutePath() + "]"); return; } } File transFile = new File(dir.getPath() + File.separator + langName.substring(4)); PrintWriter transFileOutput = new PrintWriter(transFile, "UTF8"); for (String line : engList) { if (line.startsWith("#") || StringUtils.deleteWhitespace(line).length() < 3 || line.indexOf('=') == -1) { transFileOutput.println(line); continue; } boolean doMove = true; String[] toks = StringUtils.split(line, '='); if (toks.length > 1) { String key = null; String value = null; if (toks.length == 2) { key = toks[0]; value = toks[1]; } else { key = toks[0]; StringBuilder sb = new StringBuilder(); for (int i = 1; i < toks.length; i++) { sb.append(String.format("%s=", toks[i])); } sb.setLength(sb.length() - 1); // chomp extra '=' value = sb.toString(); } if (key != null) { String text = transHash.get(key); transFileOutput.println(String.format("%s=%s", key, text != null ? text : value)); if (text == null) { log.info("Adding new term: " + key); } doMove = false; } else { log.info("Adding new term: " + key); } } if (doMove) { transFileOutput.println(line); } } transFileOutput.flush(); transFileOutput.close(); log.info(String.format("Write file: %s", transFile.getPath())); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.sonar.orchestrator.build.MavenBuildExecutor.java
private void executeGoal(MavenBuild build, Configuration config, Map<String, String> adjustedProperties, String goal, final BuildResult result, CommandExecutor commandExecutor) { try {/* w w w .j a va2 s .com*/ File mavenHome = config.fileSystem().mavenHome(); if (mavenHome == null) { throw new IllegalStateException("No maven home defined for the IT"); } Command command = Command.create(getMvnPath(mavenHome)); if (build.getExecutionDir() != null) { command.setDirectory(build.getExecutionDir()); } for (Map.Entry<String, String> env : build.getEffectiveEnvironmentVariables().entrySet()) { command.setEnvironmentVariable(env.getKey(), env.getValue()); } // Force M2_HOME to override default from env command.setEnvironmentVariable("M2_HOME", mavenHome.getAbsolutePath()); // allow to set "clean install" in the same process command.addArguments(StringUtils.split(goal, " ")); command.addArgument("-B"); command.addArgument("-e"); if (build.getPom() != null) { File pomFile = config.fileSystem().locate(build.getPom()); Preconditions.checkState(pomFile.exists(), "Maven pom does not exist: " + build.getPom()); command.addArgument("-f").addArgument(pomFile.getAbsolutePath()); } if (build.isDebugLogs()) { command.addArgument("-X"); } command.addArguments(build.arguments()); for (Map.Entry<String, String> entry : adjustedProperties.entrySet()) { command.addSystemArgument(entry.getKey(), entry.getValue()); } StreamConsumer.Pipe writer = new StreamConsumer.Pipe(result.getLogsWriter()); LoggerFactory.getLogger(getClass()).info("Execute: " + command); int status = commandExecutor.execute(command, writer, build.getTimeoutSeconds() * 1000); result.setStatus(status); } catch (Exception e) { throw new IllegalStateException("Fail to execute Maven", e); } }
From source file:de.qaware.chronix.solr.ingestion.format.PrometheusTextFormatParser.java
@Override public Iterable<MetricTimeSeries> parse(InputStream stream) throws FormatParseException { Set<String> validMetricNames = new HashSet<>(); Map<Metric, MetricTimeSeries.Builder> metrics = new HashMap<>(); BufferedReader reader = new BufferedReader(new InputStreamReader(stream, UTF_8)); String line;//w ww . java 2 s .co m try { while ((line = reader.readLine()) != null) { if (line.isEmpty()) { continue; } if (isHelpLine(line)) { continue; } if (isTypeLine(line)) { TypeLine typeLine = parseTypeLine(line); if (isTypeValid(typeLine)) { validMetricNames.add(typeLine.getMetricName()); } continue; } if (isCommentLine(line)) { continue; } // Example: http_requests_total{method="post",code="200"} 1027 1395066363000 String[] parts = StringUtils.split(line, ' '); // At least 2 parts, because timestamp is optional if (parts.length < 2) { throw new FormatParseException( "Expected at least 2 parts, found " + parts.length + " in line '" + line + "'"); } String metricName = getMetricName(parts); if (!validMetricNames.contains(metricName)) { LOGGER.debug("Ignoring metric {}", metricName); continue; } Instant timestamp = getMetricTimestamp(parts); double value = getMetricValue(parts); Map<String, String> tags = getMetricTags(parts); addPoint(metrics, metricName, timestamp, value, tags); } } catch (IOException e) { throw new FormatParseException("IO exception while parsing OpenTSDB telnet format", e); } return metrics.values().stream().map(MetricTimeSeries.Builder::build).collect(Collectors.toList()); }
From source file:com.netflix.staash.cassandra.discovery.EurekaAstyanaxHostSupplier.java
public Supplier<List<Host>> getSupplier(final String clusterName) { return new Supplier<List<Host>>() { public List<Host> get() { Application app = eurekaClient.getApplication(clusterName.toUpperCase()); List<Host> hosts = Lists.newArrayList(); if (app == null) { LOG.warn("Cluster '{}' not found in eureka", new Object[] { clusterName }); } else { List<InstanceInfo> ins = app.getInstances(); if (ins != null && !ins.isEmpty()) { hosts = Lists.newArrayList( Collections2.transform(Collections2.filter(ins, new Predicate<InstanceInfo>() { public boolean apply(InstanceInfo input) { return input.getStatus() == InstanceInfo.InstanceStatus.UP; }/*from w w w . j av a 2s .com*/ }), new Function<InstanceInfo, Host>() { public Host apply(InstanceInfo info) { String[] parts = StringUtils .split(StringUtils.split(info.getHostName(), ".")[0], '-'); Host host = new Host(info.getHostName(), info.getPort()) .addAlternateIpAddress(StringUtils.join( new String[] { parts[1], parts[2], parts[3], parts[4] }, ".")) .addAlternateIpAddress(info.getIPAddr()).setId(info.getId()); try { if (info.getDataCenterInfo() instanceof AmazonInfo) { AmazonInfo amazonInfo = (AmazonInfo) info.getDataCenterInfo(); host.setRack(amazonInfo.get(MetaDataKey.availabilityZone)); } } catch (Throwable t) { LOG.error("Error getting rack for host " + host.getName(), t); } return host; } })); } else { LOG.warn("Cluster '{}' found in eureka but has no instances", new Object[] { clusterName }); } } return hosts; } }; }