Java Code Examples for java.lang.String#startsWith()

The following examples show how to use java.lang.String#startsWith() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestKGParity.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 2
Source File: NumberUtils.java    From Android-utils with Apache License 2.0 6 votes vote down vote up
/**
 * <p>Convert a <code>String</code> to a <code>BigInteger</code>;
 * since 3.2 it handles hex (0x or #) and octal (0) notations.</p>
 *
 * <p>Returns <code>null</code> if the string is <code>null</code>.</p>
 *
 * @param str  a <code>String</code> to convert, may be null
 * @return converted <code>BigInteger</code> (or null if the input is null)
 * @throws NumberFormatException if the value cannot be converted
 */
public static BigInteger createBigInteger(final String str) {
    if (str == null) {
        return null;
    }
    int pos = 0; // offset within string
    int radix = 10;
    boolean negate = false; // need to negate later?
    if (str.startsWith("-")) {
        negate = true;
        pos = 1;
    }
    if (str.startsWith("0x", pos) || str.startsWith("0x", pos)) { // hex
        radix = 16;
        pos += 2;
    } else if (str.startsWith("#", pos)) { // alternative hex (allowed by Long/Integer)
        radix = 16;
        pos ++;
    } else if (str.startsWith("0", pos) && str.length() > pos + 1) { // octal; so long as there are additional digits
        radix = 8;
        pos ++;
    } // default is to treat as decimal

    final BigInteger value = new BigInteger(str.substring(pos), radix);
    return negate ? value.negate() : value;
}
 
Example 3
Source File: TestKGParity.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 4
Source File: TestKGParity.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 5
Source File: TestKGParity.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 6
Source File: TestKGParity.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 7
Source File: TestKGParity.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 8
Source File: TestKGParity.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 9
Source File: TestKGParity.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void run() throws Exception {
    Provider[] providers = Security.getProviders();
    for (Provider p : providers) {
        String prvName = p.getName();
        if (prvName.startsWith("SunJCE")
                || prvName.startsWith("SunPKCS11-")) {
            for (String algorithm : ALGORITHM_ARR) {
                if (!runTest(p, algorithm)) {
                    throw new RuntimeException(
                            "Test failed with provider/algorithm:"
                                    + p.getName() + "/" + algorithm);
                } else {
                    out.println("Test passed with provider/algorithm:"
                            + p.getName() + "/" + algorithm);
                }
            }
        }
    }
}
 
Example 10
Source File: FieldSetRepo.java    From vespa with Apache License 2.0 6 votes vote down vote up
public FieldSet parse(DocumentTypeManager docMan, String fieldSet) {
    if (fieldSet.length() == 0) {
        throw new IllegalArgumentException("Illegal field set value \"\"");
    }

    if (fieldSet.startsWith("[")) {
        return parseSpecialValues(fieldSet);
    }

    StringTokenizer tokenizer = new StringTokenizer(fieldSet, ":");
    if (tokenizer.countTokens() != 2) {
        throw new IllegalArgumentException(
                "The field set list must consist of a document type, " +
                "then a colon (:), then a comma-separated list of field names");
    }

    String type = tokenizer.nextToken();
    String fields = tokenizer.nextToken();

    return parseFieldCollection(docMan, type, fields);
}
 
Example 11
Source File: PropertyListWriter.java    From JarBundler with Apache License 2.0 6 votes vote down vote up
private void writeJavaProperties(Hashtable javaProperties, Node appendTo)
{

    writeKey("Properties", appendTo);

    Node propertiesDict = createNode("dict", appendTo);

    for (Iterator i = javaProperties.keySet().iterator(); i.hasNext(); )
    {
        String key = (String) i.next();

        if (key.startsWith("com.apple.") && (bundleProperties.getJavaVersion() >= 1.4))
        {
            System.out.println("Deprecated as of 1.4: " + key);
            continue;
        }

        writeKeyStringPair(key, (String) javaProperties.get(key), propertiesDict);
    }
}
 
Example 12
Source File: OAuthMediator.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the message contains Authorization header or query strings
 *
 * @param synCtx
 * @return
 */
private boolean validateRequest(MessageContext synCtx) {

    boolean isOauth2 = false;
    String accessToken = null;

    org.apache.axis2.context.MessageContext msgContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
    Map headersMap =
            (Map) msgContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    String authHeader = (String) headersMap.get("Authorization");

    // if we can't find the OAuth header, prompt error
    if (authHeader == null) {
        throw new SynapseException("Not a valid OAuth Request");
    }

    // checking for OAuth 2.0 params
    if (authHeader != null && authHeader.startsWith(OAuthConstants.BEARER)) {
        isOauth2 = true;
        // Do not need do validate an empty OAuth2 token
        if (authHeader.length() > OAuthConstants.BEARER.length()) {
            accessToken = authHeader.substring(OAuthConstants.BEARER.length()).trim();
        }
    }

    // not a valid OAuth 2.0 request
    if (isOauth2 == true && accessToken == null) {
        // Throw a correct descriptive message.
        throw new SynapseException("Invalid or empty OAuth 2.0 token");
    }

    return isOauth2;
}
 
Example 13
Source File: OAuthMediator.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private String removeLeadingAndTrailingQuatation(String base) {
    String result = base;

    if (base.startsWith("\"") || base.endsWith("\"")) {
        result = base.replace("\"", "");
    }
    return result.trim();
}
 
Example 14
Source File: RenderParameters.java    From disthene-reader with MIT License 5 votes vote down vote up
private static long parseExtendedTime(String timeString, DateTimeZone tz) {
    Matcher matcher = EXTENDED_TIME_PATTERN.matcher(timeString);

    if (matcher.matches()) {
        String value = matcher.group(1);
        String unit = matcher.group(2);
        long unitValue;

        // calc unit value
        if (unit.startsWith("s")) {
            unitValue = 1L;
        } else if (unit.startsWith("min")) {
            unitValue = 60L;
        } else if (unit.startsWith("h")) {
            unitValue = 3600L;
        } else if (unit.startsWith("d")) {
            unitValue = 86400L;
        } else if (unit.startsWith("w")) {
            unitValue = 604800L;
        } else if (unit.startsWith("mon")) {
            unitValue = 2678400L;
        } else if (unit.startsWith("y")) {
            unitValue = 31536000L;
        } else {
            unitValue = 60L;
        }
        // calc offset as (now) - (number * unit value)
        return (System.currentTimeMillis() / 1000L) - (Long.valueOf(value) * unitValue);
    } else if ("now".equals(timeString.toLowerCase())) {
        return System.currentTimeMillis() / 1000L;
    } else {
        return new DateTime(Long.valueOf(timeString) * 1000, tz).getMillis() / 1000L;
    }
}