Example usage for org.apache.commons.lang StringUtils split

List of usage examples for org.apache.commons.lang StringUtils split

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils split.

Prototype

public static String[] split(String str, String separatorChars) 

Source Link

Document

Splits the provided text into an array, separators specified.

Usage

From source file:com.activecq.api.utils.OsgiPropertyUtil.java

/**
 * Util for parsing Arrays of Service properties in the form >value<>separator<>value<
 *
 * @param values//from  w w  w.java 2s  . co m
 * @param separator
 * @return
 */
public static Map<String, String> toMap(String[] values, String separator) {
    Map<String, String> map = new HashMap<String, String>();

    if (values == null || values.length < 1) {
        return map;
    }

    for (String value : values) {
        String[] tmp = StringUtils.split(value, separator);
        if (tmp.length == 2) {
            map.put(tmp[0], tmp[1]);
        }
    }

    return map;
}

From source file:com.intel.cosbench.driver.generator.BimodalIntGenerator.java

private static BimodalIntGenerator tryParse(String pattern) {
    pattern = StringUtils.substringBetween(pattern, "(", ")");
    String[] args = StringUtils.split(pattern, ',');
    double mean1 = Double.parseDouble(args[0]);
    double stdDeviation1 = Double.parseDouble(args[1]);
    double mean2 = Double.parseDouble(args[2]);
    double stdDeviation2 = Double.parseDouble(args[3]);
    double coinFlip = Double.parseDouble(args[4]);
    return new BimodalIntGenerator(mean1, stdDeviation1, mean2, stdDeviation2, coinFlip);
}

From source file:com.twitter.distributedlog.client.serverset.DLZkServerSet.java

private static Iterable<InetSocketAddress> getZkAddresses(URI uri) {
    String zkServers = getZKServersFromDLUri(uri);
    String[] zkServerList = StringUtils.split(zkServers, ',');
    ImmutableList.Builder<InetSocketAddress> builder = ImmutableList.builder();
    for (String zkServer : zkServerList) {
        HostAndPort hostAndPort = HostAndPort.fromString(zkServer).withDefaultPort(2181);
        builder.add(InetSocketAddress.createUnresolved(hostAndPort.getHostText(), hostAndPort.getPort()));
    }//  ww w  .  j av a 2s . co m
    return builder.build();
}

From source file:com.alibaba.doris.admin.service.main.DorisConfigUtil.java

/**
 * <p>/*  w ww  .  j  av a 2s  . c o  m*/
 * ?ip????serviceIP
 * ???.
 * <p>
 * request.getRemoteAddr()?ServiceIP
 * <p>
 * ??Http?x-forwarded-forIP??
 * ??IP?
 * <p>
 * ??forwarded-for?Proxy-Client-IPWL-Proxy-Client-IP??
 * 
 * @param request
 * @return
 */
public static String getIpAddr(HttpServletRequest request) {
    String ip = null;

    ip = request.getHeader("x-forwarded-for");
    if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("Proxy-Client-IP");
    }
    if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getHeader("WL-Proxy-Client-IP");
    }
    if (StringUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
        ip = request.getRemoteAddr();
    }
    String[] temp = StringUtils.split(ip, ',');
    if (temp.length > 1) {
        for (int i = 0; i < temp.length; i++) {// ?unknown
            if (!"unknown".equalsIgnoreCase(temp[i])) {
                ip = temp[i];
                break;
            }
        }
    }

    return ip;
}

From source file:com.ewcms.publication.uri.RuleParse.java

/**
 * ?uri??// w  w  w.j a va  2s  .com
 * 
 * @param patter
 *            uri
 * @return  key:?? value:?
 */
private static Map<String, String> parseVariables(String patter) {
    Map<String, String> variables = new HashMap<String, String>();
    if (!StringUtils.contains(patter, VARIABLE_START)) {
        return variables;
    }
    String[] tokens = StringUtils.splitByWholeSeparator(patter, VARIABLE_START);
    for (String token : tokens) {
        logger.debug("Token with ${{}", token);
        if (!StringUtils.contains(token, "}")) {
            logger.warn("\"{}\" is not closed", token);
            continue;
        }
        String value = StringUtils.split(token, VARIABLE_END)[0];
        if (StringUtils.isBlank(value)) {
            logger.warn("Variable's nam is null");
            continue;
        }
        logger.debug("variable is {}", value);
        String[] s = StringUtils.splitByWholeSeparator(value, VARIABLE_FORMAT);
        if (s.length == 1) {
            variables.put(s[0], null);
        } else {
            variables.put(s[0], s[1]);
        }
    }
    return variables;
}

From source file:com.hangum.tadpole.commons.util.IPUtil.java

/**
 * ip filter/*from w ww . j av a  2s  .com*/
 * 
 * usage : IPUtil.ifFilterString("1.2.*.*,10.10.*", "1.2.1.1")
 * 
 * @param strAllowIP
 * @param strCheckIP
 * @return
 */
public static boolean ifFilterString(String strAllowIP, String strCheckIP) {
    String[] strArryIP = StringUtils.split(strAllowIP, ",");
    for (String strIP : strArryIP) {
        try {
            Config config = new Config();
            config.setAllowFirst(true);
            config.setDefaultAllow(false);
            config.allow(strIP);

            if (IpFilters.create(config).accept(strCheckIP))
                return true;
        } catch (Exception e) {
            logger.error("check user ip", e);
        }
    }

    return false;
}

From source file:com.genuitec.eclipse.gerrit.tools.internal.gps.GpsQuickImportFiles.java

private static void load() {
    synchronized (files) {
        for (String file : StringUtils.split(prefs.get("quick-files", ""), '\n')) { //$NON-NLS-1$ //$NON-NLS-2$
            File f = new File(file);
            if (f.exists()) {
                files.add(f);// www .j  a v a2 s .com
            }
        }
    }
}

From source file:com.cyclopsgroup.waterview.core.ParseURLValve.java

/**
 * @param requestPath/*from   www  . j a v  a 2 s.  c  o  m*/
 * @return list of parts
 */
static List parseRequestPath(String requestPath) {
    List ret = new ArrayList();
    String[] parts = StringUtils.split(requestPath, '/');
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < parts.length; i++) {
        String part = parts[i];
        if (getInstructors().contains(part) && sb.length() != 0) {
            ret.add(sb.toString());
            sb = new StringBuffer();
        }
        sb.append('/').append(part);
    }
    ret.add(sb.toString());
    return ret;
}

From source file:com.dianping.simple.spring.CarFactroyBean.java

@Override
public Object getObject() throws Exception {
    // TODO Auto-generated method stub
    Car car = new Car();
    String[] infos = StringUtils.split(carInfo, ",");
    car.setBrand(infos[0]);/*w w w . j av a2s .  c om*/
    car.setMaxSpeed(Integer.parseInt(infos[1]));
    car.setPrice(Double.parseDouble(infos[2]));
    return car;
}

From source file:com.pamarin.api.converter.JsonLocaleDeserializer.java

@Override
public Locale deserialize(JsonParser jp, DeserializationContext dc)
        throws IOException, JsonProcessingException {

    String localeCode = jp.getText();
    if (!hasText(localeCode)) {
        return null;
    }//ww w. ja v  a  2 s  . c  om

    String[] split = StringUtils.split(localeCode, "_");

    if (split.length != 2) {
        throw new IOException("not support locale, require language and country");
    }

    if (!hasText(split[0])) {
        throw new IOException("not support locale, require language");
    }

    if (!hasText(split[1])) {
        throw new IOException("not support locale, require country");
    }

    return new Locale(split[0], split[1]);
}