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

The following examples show how to use java.net.URISyntaxException#getIndex() . These examples are extracted from open source projects. 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 Project: rawhttp   File: HttpMetadataParser.java    License: 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
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 Project: TencentKona-8   File: Test.java    License: 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 Project: jdk8u60   File: Test.java    License: 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 Project: openjdk-jdk8u   File: Test.java    License: 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
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 Project: openjdk-jdk9   File: Test.java    License: 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 Project: jdk8u-jdk   File: Test.java    License: 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 Project: hottub   File: Test.java    License: 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
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 Project: openjdk-8   File: Test.java    License: 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 Project: jdk8u_jdk   File: Test.java    License: 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 Project: jdk8u-jdk   File: Test.java    License: 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 Project: jdk8u-dev-jdk   File: Test.java    License: 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());
}