Example usage for com.google.common.base Splitter on

List of usage examples for com.google.common.base Splitter on

Introduction

In this page you can find the example usage for com.google.common.base Splitter on.

Prototype

@CheckReturnValue
@GwtIncompatible("java.util.regex")
public static Splitter on(final Pattern separatorPattern) 

Source Link

Document

Returns a splitter that considers any subsequence matching pattern to be a separator.

Usage

From source file:org.jboss.metrics.agenda.address.Address.java

public static Address apply(String address) {
    List<String> tokens = address == null ? Collections.<String>emptyList()
            : Splitter.on(CharMatcher.anyOf("/=")).trimResults().omitEmptyStrings().splitToList(address);

    List<Tuple> tuples = new ArrayList<>(tokens.size() / 2 + 1);
    for (Iterator<String> iterator = tokens.iterator(); iterator.hasNext();) {
        String type = iterator.next();
        String name = iterator.hasNext() ? iterator.next() : "";
        tuples.add(new Tuple(type, name));
    }//from   ww w .  j ava 2 s  .c o  m

    return new Address(tuples);
}

From source file:com.mcmiddleearth.plotbuild.utils.ListUtil.java

public static List<Integer> integersFromString(String string, char delim) {
    List<String> strList = Splitter.on(delim).splitToList(string);
    ArrayList<Integer> list = new ArrayList<>();
    for (String s : strList) {
        list.add(Integer.parseInt(s));
    }/*from   w  w  w. j a v  a2  s.co  m*/
    return list;
}

From source file:com.microsoftopentechnologies.auth.jwt.JWTParser.java

/**
 * Absolutely basic, bare minimum implementation of JWT parsing as needed
 * for parsing the ID token returned by Azure Active Directory as
 * documented here - https://msdn.microsoft.com/en-us/library/azure/dn645542.aspx.
 *
 * @param jwtInput The ID token JWT string.
 * @return The JWT object representing the information encoded in the JWT.
 * @throws ParseException/*from  w  w w .j a  v a 2 s. c  o  m*/
 */
public static JWT parse(String jwtInput) throws ParseException {
    if (Strings.isNullOrEmpty(jwtInput)) {
        throw new ParseException("jwt string is null/empty.", 0);
    }

    // split the period delimited string
    List<String> tokens = Splitter.on('.').omitEmptyStrings().splitToList(jwtInput);

    // the length of the list MUST be 2 or more
    if (tokens.size() < 2) {
        throw new ParseException("Invalid JWT string supplied.", 0);
    }

    // parse JWT header and claims
    JsonParser jsonParser = new JsonParser();
    JsonObject header = (JsonObject) jsonParser.parse(stringFromBase64(tokens.get(0)));
    JsonObject claims = (JsonObject) jsonParser.parse(new String(Base64.decodeBase64(tokens.get(1))));

    return JWT.parse(header, claims);
}

From source file:edu.sabanciuniv.sentilab.utils.text.nlp.base.PosTag.java

/**
 * Splits a tags string into its constituents.
 * @param tagsString the {@code string} containing tags separating by an accepted separator.
 * @return an {@link Iterable} of tags./*from   w ww  . j  a v  a2 s  .c  o m*/
 */
public static Iterable<String> splitTagsString(String tagsString) {
    return Splitter.on(Pattern.compile("\\||,|;|\\s+")).split(StringUtils.defaultIfEmpty(tagsString, ""));
}

From source file:com.cloudera.exhibit.hive.ReadFileUDF.java

private static List<String> read(String fileName, String delim) throws IOException {
    List<String> contents = Files.readLines(new File(fileName), Charsets.UTF_8);
    if (!"\n".equals(delim)) {
        contents = Lists.newArrayList(Splitter.on(delim).split(Joiner.on("\n").join(contents)));
    }/*w w w. j  av a 2 s  . co  m*/
    return contents;
}

From source file:io.lex.xauth.auth.XTokenUtil.java

public static SecuredXToken decodeToken(String rawToken, String secret) {
    String xToken = plainStr(rawToken);
    List<String> list = Splitter.on(FIELD_SEP).splitToList(xToken);
    if (list.size() != 6) {
        throw new IllegalArgumentException("Invalid X-Token: " + rawToken);
    }// w ww.j a v a 2  s. co m
    String enc = SHAUtil.sha1(xToken.substring(0, xToken.lastIndexOf(FIELD_SEP)), secret);
    String credential = list.get(5);
    if (!enc.startsWith(credential)) {
        throw new IllegalArgumentException("Bad X-Token: " + rawToken);
    }

    XTokenPrincipal principal = new XTokenPrincipal();
    principal.setUserName(list.get(0));
    principal.setUserId(toLong(list.get(1)));
    principal.setOpUserId(toLong(list.get(2)));
    principal.setOpAccountId(toLong(list.get(3)));
    principal.setPermissionList(Splitter.on(ATTRI_SEP).splitToList(list.get(4)));
    return new SecuredXToken(principal, credential);
}

From source file:eu.project.ttc.utils.FileUtils.java

public static String getFileName(String path) {
    return Iterables.getLast(Splitter.on('/').split(path));
}

From source file:com.android.tools.idea.apk.viewer.AndroidApplicationInfo.java

@NotNull
static AndroidApplicationInfo parse(@NotNull String output) {
    String packageId = null;//from   w w w . j  a v  a 2s .c  o  m
    String versionName = null;

    for (String line : Splitter.on('\n').trimResults().split(output)) {
        if (line.startsWith("A: android:versionName")) {
            // e.g: A: android:versionName(0x0101021c)="51.0.2704.10" (Raw: "51.0.2704.10")
            int eqIndex = line.indexOf("=");
            if (eqIndex > 0) {
                int endQuote = line.indexOf("\"", eqIndex + 2);
                if (endQuote > 0) {
                    versionName = line.substring(eqIndex + 2, endQuote);
                }
            }
        } else if (line.startsWith("A: package=")) {
            // e.g: A: package="com.android.chrome" (Raw: "com.android.chrome")
            int eqIndex = line.indexOf("=");
            if (eqIndex > 0) {
                int endQuote = line.indexOf("\"", eqIndex + 2);
                if (endQuote > 0) {
                    packageId = line.substring(eqIndex + 2, endQuote);
                }
            }
        }

        if (packageId != null && versionName != null) {
            break;
        }
    }

    return new AndroidApplicationInfo(StringUtil.notNullize(packageId, "unknown"),
            StringUtil.notNullize(versionName, "?"));
}

From source file:org.apache.james.jmap.utils.DownloadPath.java

public static DownloadPath from(String path) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(path), "'path' is mandatory");

    // path =  /blobId/name
    // idx  = 0 1      2
    List<String> pathVariables = Splitter.on('/').splitToList(path);
    Preconditions.checkArgument(pathVariables.size() >= 1 && pathVariables.size() <= 3,
            "'blobId' is mandatory");

    String blobId = Iterables.get(pathVariables, 1, null);
    Preconditions.checkArgument(!Strings.isNullOrEmpty(blobId), "'blobId' is mandatory");

    return new DownloadPath(blobId, name(pathVariables));
}

From source file:com.intel.chimera.random.SecureRandomFactory.java

public static SecureRandom getSecureRandom(Properties props) {
    String secureRandomClasses = props.getProperty(CHIMERA_CRYPTO_SECURE_RANDOM_CLASSES_KEY);
    if (secureRandomClasses == null) {
        secureRandomClasses = System.getProperty(CHIMERA_CRYPTO_SECURE_RANDOM_CLASSES_KEY);
    }//from  w  w w .j  a  v  a2  s . c o m

    SecureRandom random = null;
    if (secureRandomClasses != null) {
        for (String klassName : Splitter.on(',').trimResults().omitEmptyStrings().split(secureRandomClasses)) {
            try {
                final Class klass = ReflectionUtils.getClassByName(klassName);
                random = (SecureRandom) ReflectionUtils.newInstance(klass, props);
                if (random != null) {
                    break;
                }
            } catch (ClassCastException e) {
                LOG.error("Class {} is not a Cipher.", klassName);
            } catch (ClassNotFoundException e) {
                LOG.error("Cipher {} not found.", klassName);
            }
        }
    }

    return (random == null) ? new JavaSecureRandom(props) : random;
}