Java Code Examples for java.net.URISyntaxException#getIndex()

The following examples show how to use java.net.URISyntaxException#getIndex() . 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: HttpMetadataParser.java    From rawhttp with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the given URI specification.
 * <p>
 * If no scheme is given, {@code http} is used.
 * <p>
 * If {@link RawHttpOptions#allowIllegalStartLineCharacters()} is {@code true}, then
 * this method allows illegal characters to appear in the text as long as
 * they don't interfere with splitting the URI into its separate components. This means that it's not
 * necessary to escape characters which are not used as URI component separators, considering the fact that URIs
 * are parsed using a "first-match-wins" strategy.
 * <p>
 * Otherwise, this method simply uses {@link URI#URI(String)} to parse the URI (i.e. it follows RFC-2396 strictly).
 *
 * @param uri the URI specification to parse
 * @return parsed URI
 */
public URI parseUri(String uri) {
    String schemeUri = uriWithSchema(uri);
    try {
        if (options.allowIllegalStartLineCharacters()) {
            return parseUriLenient(schemeUri);
        } else {
            return new URI(schemeUri);
        }
    } catch (URISyntaxException e) {
        if (e.getReason().startsWith("Illegal character in ")) {
            int startIndex = schemeUri.length() - uri.length();
            int index = e.getIndex() - startIndex;
            throw new InvalidHttpRequest(
                    String.format("Invalid request target: %s at index %d: '%s'", e.getReason(), index, uri), 1);
        } else {
            throw new InvalidHttpRequest(
                    String.format("Invalid request target: %s", e.getReason()), 1);
        }
    }
}
 
Example 2
Source File: Test.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 3
Source File: Test.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 4
Source File: Test.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 5
Source File: Test.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 6
Source File: Test.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 7
Source File: Test.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 8
Source File: Test.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 9
Source File: Test.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 10
Source File: Test.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 11
Source File: Test.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 12
Source File: Test.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 13
Source File: Test.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}
 
Example 14
Source File: Test.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static void show(String prefix, URISyntaxException x) {
    out.println(uquote(x.getInput()));
    if (x.getIndex() >= 0) {
        for (int i = 0; i < x.getIndex(); i++) {
            if (x.getInput().charAt(i) >= '\u0080')
                out.print("      ");        // Skip over \u1234
            else
                out.print(" ");
        }
        out.println("^");
    }
    out.println(prefix + ": " + x.getReason());
}