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.dp2345.plugin.ftp.FtpPlugin.java

@Override
public void upload(String path, File file, String contentType) {
    PluginConfig pluginConfig = getPluginConfig();
    if (pluginConfig != null) {
        String host = pluginConfig.getAttribute("host");
        Integer port = Integer.valueOf(pluginConfig.getAttribute("port"));
        String username = pluginConfig.getAttribute("username");
        String password = pluginConfig.getAttribute("password");
        FTPClient ftpClient = new FTPClient();
        InputStream inputStream = null;
        try {/*w ww .  j a  v  a 2 s.  c o  m*/
            inputStream = new FileInputStream(file);
            ftpClient.connect(host, port);
            ftpClient.login(username, password);
            ftpClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            if (FTPReply.isPositiveCompletion(ftpClient.getReplyCode())) {
                String directory = StringUtils.substringBeforeLast(path, "/");
                String filename = StringUtils.substringAfterLast(path, "/");
                if (!ftpClient.changeWorkingDirectory(directory)) {
                    String[] paths = StringUtils.split(directory, "/");
                    String p = "/";
                    ftpClient.changeWorkingDirectory(p);
                    for (String s : paths) {
                        p += s + "/";
                        if (!ftpClient.changeWorkingDirectory(p)) {
                            ftpClient.makeDirectory(s);
                            ftpClient.changeWorkingDirectory(p);
                        }
                    }
                }
                ftpClient.storeFile(filename, inputStream);
                ftpClient.logout();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IOUtils.closeQuietly(inputStream);
            if (ftpClient.isConnected()) {
                try {
                    ftpClient.disconnect();
                } catch (IOException e) {
                }
            }
        }
    }
}

From source file:ezbake.data.elastic.security.EzSecurityVisibilityFilter.java

public EzSecurityVisibilityFilter(Map<String, Object> params, ESLogger logger) {
    this.logger = logger;

    if (params == null) {
        throw new IllegalArgumentException("Script parameters may not be null");
    }/*w w  w. j  av  a2 s  . co  m*/

    visibilityField = (String) params.get(VISIBILITY_FIELD_PARAM);
    if (StringUtils.isEmpty(visibilityField)) {
        throw new IllegalArgumentException("Visibility must be given");
    }

    final String requiredPermsParam = (String) params.get(REQUIRED_PERMISSIONS_PARAM);
    if (StringUtils.isEmpty(requiredPermsParam)) {
        throw new IllegalArgumentException("Required permissions must be given");
    }

    final String[] requiredPermNamesArray = StringUtils.split(requiredPermsParam, ',');
    final List<String> requiredPermNames = Lists.newArrayList(requiredPermNamesArray);

    final List<Permission> requiredPermsList = Lists.transform(requiredPermNames,
            new Function<String, Permission>() {
                @Override
                public Permission apply(String input) {
                    return Permission.valueOf(input);
                }
            });

    requiredPermissions = EnumSet.copyOf(requiredPermsList);

    final String authsBase64 = (String) params.get(AUTHS_PARAM);
    try {
        authorizations = deserializeFromBase64(Authorizations.class, authsBase64);
    } catch (final TException e) {
        final String errMsg = "Could not deserialize authorizations parameter to Authorizations Thrift";
        this.logger.error(errMsg, e);
        throw new IllegalArgumentException(errMsg, e);
    }

    evaluator = new PermissionEvaluator(authorizations);
    serializer = new CachingSerializer<>(new Base64Serializer());
}

From source file:com.alibaba.doris.client.tools.importdata.FileReadTask.java

@Override
public void doRun(long index) {

    File file = new File(fileName);
    if (!file.exists() || !file.isFile()) {
        System.err.println("file path error!!");
    }/*  w w  w . java2s  . c  om*/
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader(file));
    } catch (FileNotFoundException e) {
        System.err.println("file path error!!");
    }
    String tempString = null;
    int line = 1;
    // null?
    try {
        while ((tempString = reader.readLine()) != null) {
            String[] tempStrings = StringUtils.split(tempString, " ");
            if (tempStrings.length != 2) {
                System.err.println(String.format("line %s format error!!", line));
            }
            try {
                lock.lock();//?
                keyQueue.add(new KeyPair(tempStrings[0], tempStrings[1]));
                produced.signal();
            } finally {
                lock.unlock();
            }
            line++;
        }
    } catch (IOException e) {
        System.err.println("file path error!!");
    } finally {
        try {
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        finish.set(true);
    }

}

From source file:com.alibaba.otter.manager.web.home.module.action.CanalAction.java

/**
 * canal/*from www  . j av  a2 s .c o  m*/
 */
public void doAdd(@FormGroup("canalInfo") Group canalInfo,
        @FormGroup("canalParameterInfo") Group canalParameterInfo,
        @FormField(name = "formCanalError", group = "canalInfo") CustomErrors err,
        @FormField(name = "formHeartBeatError", group = "canalParameterInfo") CustomErrors heartBeatErr,
        Navigator nav) throws Exception {
    Canal canal = new Canal();
    CanalParameter parameter = new CanalParameter();
    canalInfo.setProperties(canal);
    canalParameterInfo.setProperties(parameter);

    String zkClustersString = canalParameterInfo.getField("zkClusters").getStringValue();
    String[] zkClusters = StringUtils.split(zkClustersString, ";");
    parameter.setZkClusters(Arrays.asList(zkClusters));

    Long zkClusterId = canalParameterInfo.getField("autoKeeperClusterId").getLongValue();
    parameter.setZkClusterId(zkClusterId);
    canal.setCanalParameter(parameter);

    String dbAddressesString = canalParameterInfo.getField("groupDbAddresses").getStringValue();
    // ??
    // 127.0.0.1:3306:MYSQL,127.0.0.1:3306:ORACLE;127.0.0.1:3306,127.0.0.1:3306;
    // ?,?
    if (StringUtils.isNotEmpty(dbAddressesString)) {
        List<List<DataSourcing>> dbSocketAddress = new ArrayList<List<DataSourcing>>();
        String[] dbAddresses = StringUtils.split(dbAddressesString, ";");
        for (String dbAddressString : dbAddresses) {
            List<DataSourcing> groupDbSocketAddress = new ArrayList<DataSourcing>();
            String[] groupDbAddresses = StringUtils.split(dbAddressString, ",");
            for (String groupDbAddress : groupDbAddresses) {
                String strs[] = StringUtils.split(groupDbAddress, ":");
                InetSocketAddress address = new InetSocketAddress(strs[0].trim(), Integer.valueOf(strs[1]));
                SourcingType type = parameter.getSourcingType();
                if (strs.length > 2) {
                    type = SourcingType.valueOf(strs[2]);
                }
                groupDbSocketAddress.add(new DataSourcing(type, address));
            }
            dbSocketAddress.add(groupDbSocketAddress);
        }

        parameter.setGroupDbAddresses(dbSocketAddress);
    }

    String positionsString = canalParameterInfo.getField("positions").getStringValue();
    if (StringUtils.isNotEmpty(positionsString)) {
        String positions[] = StringUtils.split(positionsString, ";");
        parameter.setPositions(Arrays.asList(positions));
    }

    if (parameter.getDetectingEnable()
            && StringUtils.startsWithIgnoreCase(parameter.getDetectingSQL(), "select")) {
        heartBeatErr.setMessage("invaliedHeartBeat");
        return;
    }

    try {
        canalService.create(canal);
    } catch (RepeatConfigureException rce) {
        err.setMessage("invalidCanal");
        return;
    }

    if (parameter.getSourcingType().isMysql() && parameter.getSlaveId() == null) {
        parameter.setSlaveId(10000 + canal.getId());
        // ?slaveId
        try {
            canalService.modify(canal);
        } catch (RepeatConfigureException rce) {
            err.setMessage("invalidCanal");
            return;
        }
    }

    nav.redirectTo(WebConstant.CANAL_LIST_LINK);
}

From source file:com.xwiki.authentication.Config.java

public List<String> getListParam(String name, char separator, List<String> def, XWikiContext context) {
    List<String> list = def;

    String str = getParam(name, null, context);

    if (str != null) {
        if (!StringUtils.isEmpty(str)) {
            list = Arrays.asList(StringUtils.split(str, separator));
        } else {/*from   w ww  .  j  a v a  2 s .c  o m*/
            list = Collections.emptyList();
        }
    }

    return list;
}

From source file:com.xpn.xwiki.plugin.lucene.IndexSearchServer.java

private Searcher[] createSearchers(String indexDirs) throws Exception {
    String[] dirs = StringUtils.split(indexDirs, ",");
    List<IndexSearcher> searchersList = new ArrayList<IndexSearcher>();
    for (int i = 0; i < dirs.length; i++) {
        try {//from  w  w  w.  ja v  a  2  s .c om
            if (!IndexReader.indexExists(dirs[i])) {
                // If there's no index there, create an empty one; otherwise the reader
                // constructor will throw an exception and fail to initialize
                new IndexWriter(dirs[i], analyzer).close();
            }
            IndexReader reader = IndexReader.open(dirs[i]);
            searchersList.add(new IndexSearcher(reader));
        } catch (IOException e) {
            // LOG.error("cannot open index " + dirs[i], e);
        }
    }

    return searchersList.toArray(new Searcher[searchersList.size()]);
}

From source file:com.jayway.jaxrs.hateoas.HateoasVerbosity.java

/**
 * Get a HateoasVerbosity corresponding to the comma-delimited String of {@link HateoasOption} values.
 *
 * @param optionsString comma-delimited (,) or semi-colon (;) String of {@link HateoasOption} values
 * @return a HateoasVerbosity instance wrapping all the specified options,
 *         or the default verbosity if an empty string is specified.
 * @throws IllegalArgumentException if an invalid option is supplied
 *//*  w ww . j  ava 2  s.  co  m*/
public static HateoasVerbosity valueOf(String optionsString) {
    if (StringUtils.isNotBlank(optionsString)) {
        String[] headerSplit;
        if (optionsString.contains(",")) {
            headerSplit = StringUtils.split(optionsString, ",");
        } else {
            headerSplit = StringUtils.split(optionsString, ";");
        }
        List<HateoasOption> options = new LinkedList<HateoasOption>();
        for (String oneOption : headerSplit) {
            options.add(HateoasOption.valueOf(oneOption.trim()));
        }

        return new HateoasVerbosity(options.toArray(new HateoasOption[0]));
    } else {
        return defaultVerbosity;
    }

}

From source file:com.voa.weixin.task.WeixinResult.java

public String getString(String xpath) {
    String value = "";
    JSONObject temp = result;/*from  w  w w .  j  av a  2s .  c o  m*/
    String[] names = StringUtils.split(xpath, "/");
    for (int i = 0; i < names.length; i++) {
        if (i == (names.length - 1)) {
            value = temp.getString(names[i]);
            break;
        }

        temp = temp.getJSONObject(names[i]);
    }

    return value;
}

From source file:ar.sgt.resolver.filter.ResolverFilter.java

@Override
public void init(FilterConfig filterConfig) throws ServletException {
    log.debug("Initializing filter");
    this.resolverConfig = (ResolverConfig) filterConfig.getServletContext()
            .getAttribute(ContextLoader.RESOLVER_CONFIG);
    this.appendBackSlash = filterConfig.getInitParameter("append_backslash") != null
            ? Boolean.parseBoolean(filterConfig.getInitParameter("append_backslash"))
            : true;/*from  w  w w.  java 2 s.com*/
    this.filterConfig = filterConfig;
    if (filterConfig.getInitParameter("exclude-path") != null) {
        this.excludePath = new HashSet<String>(
                Arrays.asList(StringUtils.split(filterConfig.getInitParameter("exclude-path"), ",")));
    } else {
        this.excludePath = null;
    }
}

From source file:com.dianping.lion.service.impl.DefaultConfigValueResolver.java

@Override
public String resolve(String configval, int envId) {
    if (configval == null) {
        return null;
    }/*from  w w w. j  a va 2  s  . c  o  m*/
    if (configval.contains(ServiceConstants.REF_CONFIG_PREFIX)) {
        try {
            Matcher matcher = ServiceConstants.REF_EXPR_PATTERN.matcher(configval);
            boolean referenceFound = false;
            StringBuffer buffer = new StringBuffer(configval.length() * 2);
            while (matcher.find()) {
                referenceFound = true;
                String refkey = matcher.group(1);
                Config refconfig = configService.findConfigByKey(refkey);
                if (refconfig == null) {
                    logger.warn("Referenced config[" + refkey + "] not found.");
                    return null;
                }
                ConfigInstance refinstance = configService.findInstance(refconfig.getId(), envId,
                        ConfigInstance.NO_CONTEXT);
                if (refinstance == null) {
                    logger.warn("Referenced config[" + refkey + "] with env[" + envId + "] not found.");
                    return null;
                }
                String refval = refinstance.getValue();
                if (refval == null) {
                    logger.warn("Reference null-valued config[" + refkey + "] with env[" + envId + "].");
                    return null;
                }
                String refparams = matcher.group(3);
                if (StringUtils.isNotBlank(refparams)) {
                    String[] paramList = StringUtils.split(refparams, "&");
                    for (String paramstr : paramList) {
                        String[] paramentry = StringUtils.split(paramstr, "=");
                        refval = StringUtils.replace(refval, "${" + paramentry[0] + "}", paramentry[1]);
                    }
                }
                matcher.appendReplacement(buffer, Matcher.quoteReplacement(refval));
            }
            if (referenceFound) {
                matcher.appendTail(buffer);
                return buffer.toString();
            }
        } catch (RuntimeException e) {
            logger.error("Resolve referenced config expression[" + configval + "] failed.", e);
            throw e;
        }
    }
    return configval;
}