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

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

Introduction

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

Prototype

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

Source Link

Document

Splits the provided text into an array, separators specified.

Usage

From source file:ca.on.oicr.pde.workflows.GATK3Workflow.java

public void init() {
    for (String s : StringUtils.split(getProperty(ANNOTKEY), ",")) {
        variantCallers.add(VariantCaller.valueOf(StringUtils.upperCase(s)));
    }/*from  w  ww .j a  v  a 2  s . c o  m*/
}

From source file:com.quancheng.saluki.springsupport.internal.ReferenceBean.java

private void addRegistyAddress() {
    String registryAddress = thrallProperties.getRegistryAddress();
    if (StringUtils.isBlank(registryAddress)) {
        throw new java.lang.IllegalArgumentException("registry address can not be null or empty");
    } else {/*from  w w w. j a  v a  2s.c o m*/
        String[] registryHostAndPort = StringUtils.split(registryAddress, ":");
        if (registryHostAndPort.length < 2) {
            throw new java.lang.IllegalArgumentException("the pattern of registry address is host:port");
        }
        setRegistryAddress(registryHostAndPort[0]);
        setRegistryPort(Integer.valueOf(registryHostAndPort[1]));
    }
}

From source file:com.nike.cerberus.security.VaultAuthPrincipal.java

private Set<String> extractUserGroups(final VaultClientTokenResponse clientToken) {
    final Map<String, String> meta = clientToken.getMeta();
    final String groupString = meta == null ? "" : meta.get(METADATA_KEY_GROUPS);
    if (StringUtils.isBlank(groupString)) {
        return Collections.emptySet();
    } else {/*from  w  w  w .  j  ava 2s  .  com*/
        return ImmutableSet.copyOf(StringUtils.split(groupString, ','));
    }
}

From source file:egovframework.com.utl.wed.filter.CkFilter.java

public void init(FilterConfig filterConfig) throws ServletException {
    String properties = filterConfig.getInitParameter("properties");
    InputStream inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(properties);
    Properties props = new Properties();
    try {/*from w  w w .  java 2s  .c om*/
        props.load(inStream);
    } catch (IOException e) {
        log.error(e);
    }

    String imageBaseDir = (String) props.get(IMAGE_BASE_DIR_KEY);
    String imageDomain = (String) props.get(IMAGE_BASE_URL_KEY);

    String[] allowFileTypeArr = null;
    String allowFileType = (String) props.get(IMAGE_ALLOW_TYPE_KEY);
    if (StringUtils.isNotBlank(allowFileType)) {
        allowFileTypeArr = StringUtils.split(allowFileType, ",");
    }

    String saveManagerClass = (String) props.get(IMAGE_SAVE_CLASS_KEY);

    ckImageSaver = new CkImageSaver(imageBaseDir, imageDomain, allowFileTypeArr, saveManagerClass);

}

From source file:ca.liquidlabs.android.speedtestvisualizer.fragments.SpeedTestInfoWindowAdapter.java

/**
 * Renders marker contents into the infobox
 * //from   www.ja va 2  s. com
 * @param marker Map marker
 * @param view Custom infobox view
 */
private void renderContents(Marker marker, View view) {
    String[] snippetInfo = StringUtils.split(marker.getSnippet(), AppConstants.TEXT_SEPARATOR);

    TextView infoHeading = (TextView) view.findViewById(R.id.txt_info_heading);
    infoHeading.setText("@ " + marker.getTitle());

    TextView downloadSpeed = (TextView) view.findViewById(R.id.txt_info_download);
    downloadSpeed.setText(snippetInfo[1]);

    TextView uploadSpeed = (TextView) view.findViewById(R.id.txt_info_upload);
    uploadSpeed.setText(snippetInfo[2]);

    // Connection type - update image based on type
    ConnectionType connType = ConnectionType.fromString(snippetInfo[0]);
    ImageView conntypeImage = (ImageView) view.findViewById(R.id.img_legend_conntype);
    if (connType.isWifi()) {
        conntypeImage.setImageResource(R.drawable.ic_connection_wifi);
    } else {
        conntypeImage.setImageResource(R.drawable.ic_connection_cell);
    }
    TextView connTypeTxt = (TextView) view.findViewById(R.id.txt_info_conntype);
    connTypeTxt.setText(snippetInfo[0]);
}

From source file:com.l2jfree.loginserver.network.L2ClientSelectorThread.java

public void printDebug(ByteBuffer buf, L2Client client, int opcode) {
    report(ErrorMode.INVALID_OPCODE, client, null, null);

    //if (!Config.PACKET_HANDLER_DEBUG)
    //   return;//from  w  w w  .  ja v a2 s.  c  o  m

    StringBuilder sb = new StringBuilder("Unknown Packet: ");
    sb.append("0x").append(Integer.toHexString(opcode));
    sb.append(", Client: ").append(client);
    _log.info(sb);

    byte[] array = new byte[buf.remaining()];
    buf.get(array);
    for (String line : StringUtils.split(HexUtil.printData(array), "\n"))
        _log.info(line);
}

From source file:name.martingeisse.miner.server.TestRegionImporter.java

private void handleRegionFile(File regionFile) throws Exception {
    String[] segments = StringUtils.split(regionFile.getName(), '.');
    if (segments.length != 4) {
        return;//from ww w. ja v a2 s .  co m
    }
    baseChunkX = Integer.parseInt(segments[1]) * 32;
    baseChunkZ = Integer.parseInt(segments[2]) * 32;
    regionParser.parse(regionFile);
}

From source file:com.opentable.config.ConfigFactory.java

private CombinedConfiguration loadOTStrategy() throws ConfigurationException {
    final String[] configPaths = StringUtils.stripAll(StringUtils.split(configName, ","));
    final CombinedConfiguration cc = new CombinedConfiguration(new OverrideCombiner());

    // All properties can be overridden by the System properties.
    cc.addConfiguration(new SystemConfiguration(), "systemProperties");
    LOG.info("Configuration source: SYSTEM");

    for (int i = configPaths.length - 1; i >= 0; i--) {
        final String configPath = configPaths[i];
        final AbstractConfiguration subConfig = configStrategy.load(configPath, configPath);
        if (subConfig == null) {
            throw new IllegalStateException(String.format("Configuration '%s' does not exist!", configPath));
        }/*from   www . ja  v  a  2  s.  co m*/
        cc.addConfiguration(subConfig, configPath);
        LOG.info("New-style configuration source: {}", configPath);
    }

    return cc;
}

From source file:com.mirth.connect.plugins.datatypes.hl7v2.XMLEncodedHL7Handler.java

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
        throws SAXException {
    logger.trace("starting element: " + localName);
    inElement = true;/*from  w ww . j av  a  2  s .  c om*/

    String[] localNameArray = StringUtils.split(localName, ID_DELIMETER);

    if (rootLevel == -1) {
        rootLevel = localNameArray.length;
    }

    /*
     * Skip the root element, MSH.1, and MSH.2 since those don't have any data that we care
     * about.
     */
    if ((localNameArray.length == 1) && (localNameArray[0].equals(ER7Reader.MESSAGE_ROOT_ID))) {
        rootLevel = 0;
        return;
    } else if (localNameArray.length == 2) {
        if (isHeaderSegment(localNameArray[0])) {
            if ((localNameArray[1].length() == 1)
                    && (localNameArray[1].charAt(0) == '1' || localNameArray[1].charAt(0) == '2')) {
                previousFieldNameArray = localNameArray;
                return;
            }
        }
    }

    /*
     * If the element that we've found is the same as the last, then we have a repetition, so we
     * remove the last separator that was added and append to repetition separator.
     */
    if (ArrayUtils.isEquals(localNameArray, previousFieldNameArray)) {
        output.deleteCharAt(output.length() - 1);
        output.append(repetitionSeparator);
        previousComponentNameArray = null;
        return;
    }

    /*
     * To find the delimeter count we are splitting the element name by the ID delimeter.
     */
    int currentDelimeterCount = localNameArray.length - 1;

    /*
     * MIRTH-2078: Don't add missing fields/components/subcomponents if the current level was
     * the starting level. This only pertains to partial XML messages where the root is a field
     * or component.
     */
    if (currentDelimeterCount == 1 && rootLevel <= 1) {
        /*
         * This will add missing fields if any (ex. between OBX.1 and OBX.5).
         */
        int previousFieldId = 0;

        if (previousFieldNameArray != null) {
            previousFieldId = NumberUtils.toInt(previousFieldNameArray[1]);
        }

        int currentFieldId = NumberUtils.toInt(localNameArray[1]);

        for (int i = 1; i < (currentFieldId - previousFieldId); i++) {
            output.append(fieldSeparator);
        }

        previousFieldNameArray = localNameArray;
    } else if (currentDelimeterCount == 2 && rootLevel <= 2) {
        /*
         * This will add missing components if any (ex. between OBX.1.1 and OBX.1.5).
         */
        int previousComponentId = 0;

        if (previousComponentNameArray != null) {
            previousComponentId = NumberUtils.toInt(previousComponentNameArray[2]);
        }

        int currentComponentId = NumberUtils.toInt(localNameArray[2]);

        for (int i = 1; i < (currentComponentId - previousComponentId); i++) {
            output.append(componentSeparator);
            previousDelimiterLength = componentSeparator.length();
        }

        previousComponentNameArray = localNameArray;
    } else if (currentDelimeterCount == 3 && rootLevel <= 3) {
        /*
         * This will add missing subcomponents if any (ex. between OBX.1.1.1 and OBX.1.1.5).
         */
        int previousSubcomponentId = 0;

        if (previousSubcomponentNameArray != null) {
            previousSubcomponentId = NumberUtils.toInt(previousSubcomponentNameArray[3]);
        }

        int currentSubcomponentId = NumberUtils.toInt(localNameArray[3]);

        for (int i = 1; i < (currentSubcomponentId - previousSubcomponentId); i++) {
            output.append(subcomponentSeparator);
            previousDelimiterLength = subcomponentSeparator.length();
        }

        previousSubcomponentNameArray = localNameArray;
    }

    /*
     * If we have an element with no periods, then we know its the name of the segment, so write
     * it to the output buffer followed by the field separator.
     */
    if (currentDelimeterCount == 0) {
        output.append(localName);
        output.append(fieldSeparator);

        /*
         * Also set previousFieldName to null so that multiple segments in a row with only one
         * field don't trigger a repetition character. (i.e. NTE|1<CR>NTE|2)
         */
        previousFieldNameArray = null;
    } else if (currentDelimeterCount == 1) {
        previousComponentNameArray = null;
    } else if (currentDelimeterCount == 2) {
        previousSubcomponentNameArray = null;
    }
}

From source file:ke.co.tawi.babblesms.server.servlet.upload.UploadUtil.java

/**
 * Checks that an uploaded Contact file is in proper order.
 * /*  w ww  .  ja  v a2  s.  com*/
 * @param file
 * @return the feedback of having inspected the file, whether it was proper
 */
protected String inspectContactFile(File file) {
    String feedback = ContactUpload.UPLOAD_SUCCESS;
    int count = 1;

    LineIterator lineIterator = null;
    try {
        lineIterator = FileUtils.lineIterator(file, "UTF-8");

        String line;
        String[] rowTokens, phoneTokens, networkTokens;
        String network;
        while (lineIterator.hasNext()) {
            line = lineIterator.nextLine();

            rowTokens = StringUtils.split(line, ',');

            if (rowTokens.length != 3 && line.length() > 0) {// Every row must have 3 columns
                return ("Invalid format on line " + count + ": " + line);
            }

            phoneTokens = StringUtils.split(rowTokens[1], ';');
            networkTokens = StringUtils.split(rowTokens[2], ';');

            // Check that the number of phone numbers and number of networks match
            if (phoneTokens.length != networkTokens.length) {
                return ("Invalid format on line " + count + ": " + line);
            }

            // Check that the phone numbers contain only numbers or spaces
            for (String phone : phoneTokens) {
                if (!StringUtils.isNumericSpace(phone)) {
                    return ("Invalid number on line " + count + ": " + line);
                }
            }

            // Check to see that only valid networks have been provided
            for (String s : networkTokens) {
                network = StringUtils.lowerCase(StringUtils.trimToEmpty(s));
                if (!networkList.contains(network)) {
                    return ("Invalid network on line " + count + ": " + line);
                }
            }

            count++;
        }

    } catch (IOException e) {
        logger.error("IOException when inspecting: " + file);
        logger.error(e);

    } finally {
        if (lineIterator != null) {
            lineIterator.close();
        }
    }

    return feedback;
}