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

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

Introduction

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

Prototype

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

Source Link

Document

Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.

Usage

From source file:nu.mine.kino.assertionutils.CSVAssertionLogic.java

@Override
public void executeTextAssertion(String expected, String actual) {
    int magicNumber = 2;
    String delimiter = " ";
    String[] expectedArray = StringUtils.splitPreserveAllTokens(expected, delimiter);
    String[] actualArray = StringUtils.splitPreserveAllTokens(actual, delimiter);
    assertThat("??", actualArray.length,
            is(equalTo(expectedArray.length)));

    // ?????magicNumber ????
    if (actualArray.length > magicNumber) {

        String[] convertActualArray = removeColumns(actualArray, magicNumber);
        String[] convertExpectedArray = removeColumns(expectedArray, magicNumber);

        assertThat(magicNumber + " ?", convertActualArray.length,
                is(convertExpectedArray.length));

        String message = "??: ";
        // Assert.assertArrayEquals(message, convertExpectedArray,
        // convertActualArray);
        assertThat(message, convertActualArray, is(convertExpectedArray));

    }/*from ww  w.  j  av a  2 s . com*/
}

From source file:org.apache.flink.table.runtime.functions.SqlFunctionUtils.java

/**
 * Split target string with custom separator and pick the index-th(start with 0) result.
 *
 * @param str   target string./*  ww w.j  ava2 s. c  o  m*/
 * @param character int value of the separator character
 * @param index index of the result which you want.
 * @return the string at the index of split results.
 */
public static String splitIndex(String str, int character, int index) {
    if (character > 255 || character < 1 || index < 0) {
        return null;
    }
    String[] values = StringUtils.splitPreserveAllTokens(str, (char) character);
    if (index >= values.length) {
        return null;
    } else {
        return values[index];
    }
}

From source file:org.cryptomator.frontend.webdav.jackrabbitservlet.FilesystemResourceFactory.java

/**
 * Processes the given range header field, if it is supported. Only headers containing a single byte range are supported.<br/>
 * <code>/*www  .  j  a v a  2s . c  o m*/
 * bytes=100-200<br/>
 * bytes=-500<br/>
 * bytes=1000-
 * </code>
 * 
 * @return Tuple of lower and upper range.
 * @throws DavException HTTP statuscode 400 for malformed requests.
 * @throws NotASingleByteRangeException Indicating a range that is not supported by this server, i.e. range header should be ignored.
 */
private Pair<String, String> parseSingleByteRange(String rangeHeader)
        throws DavException, NotASingleByteRangeException {
    assert rangeHeader != null;
    if (!rangeHeader.startsWith(RANGE_BYTE_PREFIX)) {
        throw new NotASingleByteRangeException();
    }
    final String byteRangeSet = StringUtils.removeStartIgnoreCase(rangeHeader, RANGE_BYTE_PREFIX);
    final String[] byteRanges = StringUtils.split(byteRangeSet, RANGE_SET_SEP);
    if (byteRanges.length != 1) {
        throw new NotASingleByteRangeException();
    }
    final String byteRange = byteRanges[0];
    final String[] bytePos = StringUtils.splitPreserveAllTokens(byteRange, RANGE_SEP);
    if (bytePos.length != 2 || bytePos[0].isEmpty() && bytePos[1].isEmpty()) {
        throw new DavException(DavServletResponse.SC_BAD_REQUEST, "malformed range header: " + rangeHeader);
    }
    return new ImmutablePair<>(bytePos[0], bytePos[1]);
}

From source file:org.cryptomator.frontend.webdav.servlet.ByteRange.java

private static Pair<Long, Long> getPositions(String byteRangeStr) throws MalformedByteRangeException {
    final String[] bytePos = StringUtils.splitPreserveAllTokens(byteRangeStr, RANGE_SEP);
    if (bytePos.length != 2) {
        throw new MalformedByteRangeException();
    }/*  w  w w  .ja v a 2  s .  com*/
    try {
        Long left = bytePos[0].isEmpty() ? null : Long.valueOf(bytePos[0]);
        Long right = bytePos[1].isEmpty() ? null : Long.valueOf(bytePos[1]);
        return new ImmutablePair<>(left, right);
    } catch (NumberFormatException e) {
        throw new MalformedByteRangeException();
    }
}

From source file:org.diorite.config.impl.proxy.ConfigInvocationHandler.java

@Nullable
private Object getImpl(String key) {
    return this.getImpl(StringUtils.splitPreserveAllTokens(key, ConfigTemplate.SEPARATOR), null, null);
}

From source file:org.diorite.config.impl.proxy.ConfigInvocationHandler.java

@Nullable
private Object getImpl(String key, @Nullable Object def) {
    return this.getImpl(StringUtils.splitPreserveAllTokens(key, ConfigTemplate.SEPARATOR), def, null);
}

From source file:org.diorite.config.impl.proxy.ConfigInvocationHandler.java

@Nullable
private <T> T getImpl(String key, @Nullable T def, Class<T> type) {
    return this.getImpl(StringUtils.splitPreserveAllTokens(key, ConfigTemplate.SEPARATOR), def, type);
}

From source file:org.diorite.config.impl.proxy.ConfigInvocationHandler.java

@Nullable
private <T> T getImpl(String key, Class<T> type) {
    return this.getImpl(StringUtils.splitPreserveAllTokens(key, ConfigTemplate.SEPARATOR), null, type);
}

From source file:org.diorite.config.impl.proxy.ConfigInvocationHandler.java

private void setImpl(String key, @Nullable Object value) {
    this.setImpl(StringUtils.splitPreserveAllTokens(key, ConfigTemplate.SEPARATOR), value);
}

From source file:org.diorite.config.impl.proxy.ConfigInvocationHandler.java

@Nullable
private Object removeImpl(String key) {
    return this.removeImpl(StringUtils.splitPreserveAllTokens(key, ConfigTemplate.SEPARATOR));
}